具有 animate.css 和 jquery 的顺序动画
Sequential animation with animate.css and jquery
如何使它们中的每一个都按顺序淡入淡出?
演示 http://jsfiddle.net/uz2rm8jy/4/
.HTML
<div class="c one"></div>
<div class="c two"></div>
<div class="c three"></div>
我的js
$(function() {
$('.c').each(function(i) {
$(this).delay((i++) * 150).addClass('fadeInUp'); })
});
你可以
通过使用jquery的fadeTo
使用与你已经到位的完全相同的逻辑来实现这一点......
$(function() {
$('.c').each(function(i) {
$(this).delay((i++) * 150).fadeTo(500,1); })
});
$(function() {
$('.c').each(function(i) {
$(this).delay((i++) * 150).fadeTo(500,1); })
});
.one,.two,.three {
height: 50px;
background: #dddddd;
width: 50px;
border-radius: 50%;
display:inline-block;
margin: auto 10px;
opacity:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<div class="c one"></div>
<div class="c two"></div>
<div class="c three"></div>
问题是关于 Animate .css库,但答案对 animate 没有帮助.css,我遇到了同样的问题并最终解决了它。 见下面的小提琴。JSFiddle
法典:网页示例
<div class="content">
<div class="firstanimation">
<h1 data-animation="fadeInUp" style='display: none'>
This is Title
</h1>
</div>
<div class="secondanimation">
<p data-animation="wobble" style='display: none'>
This is Description
</p>
</div>
<div class="lastanimation">
<p data-animation="bounce" style='display: none'><a href="#">Link</a></p>
</div>
</div>
Jquery:
// With Queue
function animate2(queue) {
if (queue && queue.length > 0) {
var elm = queue.shift();
var animClass = "animated " + $(elm).data('animation');
$(elm).show().addClass(animClass)
.on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
$(elm).removeClass();
animate2(queue);
});
}
};
$(function() {
var animationQueue = [
$('.content').find('.firstanimation h1'),
$('.content').find('.secondanimation p'),
$('.content').find('.lastanimation p')
];
animate2(animationQueue);
});
有两个选项供您选择。
- 转换结束事件,可以使用 JavaScript 触发
- 过渡延迟
可以在具有过渡的任何元素上侦听过渡结束事件。您可以在转换结束时触发函数,如下所示:
element.addEventListener( "transitionend", function() {
// run code here to add class on next element
});
你必须确保添加必要的前缀,但jQuery可以提供帮助。这在for
循环中很容易实现。
没有额外JS或转换结束事件的另一种选择是将.c.two
和.c.three
的转换延迟到实际转换的长度(是.c.three
的两倍)。您可以使用相应元素上的 transition-delay
属性直接在 CSS 中添加它。
我希望这有所帮助。
我不确定你的意思,根据你的代码,你只是想将类"fadeInUp"添加到你的div 中。但是试试这个也许会有所帮助。
function fade(e){
$(e+":not(:visible):first").fadeIn(function(){
fade(e);
});
}
要使用函数,只需将类"C"作为参数传递:例如。
fade('.c');
相关文章:
- 如何设置html元素填充的动画
- 如何使用动画实现纸张推车
- 按随机顺序对元素进行动画处理
- 如何创建javascript顺序动画
- Javascript中的顺序动画
- 使用ScrollMagic按顺序对多个场景进行动画处理
- 按顺序显示动画 SVG 元素
- 具有 animate.css 和 jquery 的顺序动画
- 让元素的子元素单独但按顺序进行动画处理
- Jquery队列顺序动画
- jQuery动画按顺序延迟
- Jquery/CSS带回调的顺序元素动画
- 使用 d3js 按顺序对 SVG 进行动画处理
- JQuery按顺序设置列表项的动画,然后淡出列表并重复
- 按顺序替换文本框动画中的字符
- 使用onComplete按顺序执行Fabric.js动画
- jQuery动画加载前后顺序
- javascript/css中的顺序动画
- 在流星JS,如何控制Javascript加载顺序相对于DOM加载顺序?为动画
- 使用angular和Animate.css按顺序制作动画