简体   繁体   中英

firing javascript after css3 page fade-in to make animation smoother?

I have some javascript that slows down my page fade-in animation. I am wondering how it would be possible to prevent javascript from firing until my css3 animations have reached an end? Or at least fire the javascript after X amount of seconds.

Do you have any advice? Im still new to JS so any critics and feedback is welcome as I love to learn news things.

I thought of adding all scripts after window onload but it doesnt really help.

Thank you in advance for your feedback,

In chrome you can try: window.ontransitionend - for css transitions window.onwebkitanimationend - for css animations

I have used them in the past. The event contains the class name of the animation.

an example: the css

@-webkit-keyframes doubleme {
    0% {
        -webkit-transform: scale(1);
    }
    100% {
        -webkit-transform: scale(2);
    }
}
.tag:hover {
-webkit-animation: doubleme 1s;
}

the javascript

window.onwebkitanimationend = function (event) {
  console.log(event.animationName,event.srcElement.className);
  // if correct animation
  // execute javascript
};

then execute you javascript after you get the correct end to your animation.

You can use .delay on the Javscript to delay how long before it fires. http://api.jquery.com/delay/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM