Giter Site home page Giter Site logo

How to use CSS animations? about barba HOT 8 CLOSED

barbajs avatar barbajs commented on May 17, 2024
How to use CSS animations?

from barba.

Comments (8)

luruke avatar luruke commented on May 17, 2024

Hi @htor ,
thanks for the very detailed issue.

I think your issue is that fadeOut do not return a promise, so fadeIn is called immediately newContainerLoading is resolved.

You should rewrite your fadeOut as:

fadeOut: function() {
    $(this.oldContainer).toggleClass('fade-out');

    return new Promise(function(resolve, reject) {
        window.setTimeout(function() {
           resolve();
        }, 700);
    });
},

The best way would be to use the event onanimationend instead of a simple timeout.

I haven't tried but in this way everything should work, let me know :)

from barba.

htor avatar htor commented on May 17, 2024

Thanks a lot,

Got it to work now, by returning a promise, plus fixing my CSS. Had a comma after the from clause plus I needed to override the fade-in animation when the container has both animation classes set on it during the transition. Just hacked it with !important. Seems to work:

.fade-out { animation: fade-out .5s ease forwards !important; }
.fade-in { animation: fade-in .5s ease forwards; }

@keyframes fade-out {
    from { opacity: 1; } /* no comma here */
    to { opacity: 0; }
}

@keyframes fade-in {
    from { opacity: 0; } /* no comma here */
    to { opacity: 1; }
}

Fade-out function:

fadeOut: function() {
    $(this.oldContainer).toggleClass('fade-out');

    return new Promise(function(resolve, reject) {
        window.setTimeout(function() {
           resolve();
        }, 700);
    });
},

With CSS:
right

from barba.

luruke avatar luruke commented on May 17, 2024

Nice @htor .

I totally forgot to mention this "extension" made by @JoeeGrigg https://github.com/JoeeGrigg/barba-transitions

from barba.

htor avatar htor commented on May 17, 2024

@luruke that looks promising. By the way I published my barba test app here: https://github.com/htor/pjax-barba-test/

from barba.

RhysyG avatar RhysyG commented on May 17, 2024

Hi guys, thanks for the help. I've followed these tips and was wondering if it's possible to remove the fadein class once it's finished? For example, fadein class is added, then fadeout is added and requires higher specificity in css to override. Can something like this be done?

fadeIn: function() {
  this.newContainer.classList.add('animate-fade-in');
  this.done();
  this.addEventListener('animationend', function(e) {
    this.newContainer.classList.remove('animate-fade-in');
  }, false);
}

from barba.

RhysyG avatar RhysyG commented on May 17, 2024

@luruke

The best way would be to use the event onanimationend instead of a simple timeout.

Could you please provide an example of the onanimationend event?

I have tried the following, it works the first time, but on the second click I get "Uncaught TypeError: Cannot read property 'removeChild' of null".

this.newContainer.addEventListener('animationend', function(e) {
_this.done();
}

Any ideas?

from barba.

RhysyG avatar RhysyG commented on May 17, 2024

I have tried the following, it works the first time, but on the second click I get "Uncaught TypeError: Cannot read property 'removeChild' of null".

For anyone stumbling across this, I had to REMOVE the event listener after I added it otherwise it would try to call twice.

newContainer.addEventListener("animationend",function handler() {
  _this.done();
  newContainer.removeEventListener("animationend",handler);
  newContainer.classList.remove('animate-fade-in');
  newContainer.removeAttribute("style");
});

from barba.

CassiusHR avatar CassiusHR commented on May 17, 2024

Hi guys, thanks for the help. I've followed these tips and was wondering if it's possible to remove the fadein class once it's finished? For example, fadein class is added, then fadeout is added and requires higher specificity in css to override. Can something like this be done?

fadeIn: function() {
  this.newContainer.classList.add('animate-fade-in');
  this.done();
  this.addEventListener('animationend', function(e) {
    this.newContainer.classList.remove('animate-fade-in');
  }, false);
}

Did you find how to do this? im having the same problem.

from barba.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.