简体   繁体   English

使用预加载器延迟 css 动画?

[英]Delaying the css animations with a preloader?

I currently have a website which uses Animate.css on the frontpage ( https://daneden.github.io/animate.css/ ).我目前有一个在首页上使用 Animate.css 的网站( https://daneden.github.io/animate.css/ )。 How it currently works is that the animation kicks in as soon as the user opens the website, but this causes the animation to "lag".目前的工作原理是,只要用户打开网站,动画就会立即启动,但这会导致动画“滞后”。 What I would like is to let it wait until the full page loads in before the css animations start to do their thing, thus making the experience much more fluid.我想要的是让它等到整个页面加载进来,然后 css 动画开始做他们的事情,从而使体验更加流畅。

I've looked into several js based preloaders, tried some but it doesn't delay the css animations.我研究了几个基于 js 的预加载器,尝试了一些,但它不会延迟 css 动画。 As soon as the page is finished loading, the css animations have already been completed.一旦页面加载完成,css动画就已经完成了。 Am I doing something wrong, or are JS preloaders not the right approach?我做错了什么,还是 JS 预加载器不是正确的方法?

You would have to use javascript and/or jquery to dynamically add the css class that has the animation to the desired element after the page has been loaded.在页面加载后,您必须使用 javascript 和/或 jquery 将具有动画的 css 类动态添加到所需元素。 We can do this with the $document.ready event in jquery.我们可以使用 jquery 中的 $document.ready 事件来做到这一点。

$(document).ready(function(){
     $('css selector').addClass('class-that-has-animation-binding').
});

That is how he is doing it on the main site if you view is source code.如果您查看源代码,这就是他在主站点上的做法。

The above approach didn't work for me.上述方法对我不起作用。

Since a good preloader will wait until ALL page elements, including images, have been displayed, I would wait until then ....由于一个好的预加载器会等到所有页面元素(包括图像)都显示出来,我会等到那时......

$(window).load(function() {
  $('css selector').addClass('class-that-has-animation-binding').
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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