【发布时间】:2016-10-25 18:27:10
【问题描述】:
在这里,我有一组动画将继续循环,我试图仅在第一次迭代时调用该函数,当第一次迭代结束时,不应再调用该函数。我该怎么做?
这是我的代码
var r5anim1 = function(){
$(".r5").velocity({
opacity: 1,
scale: [1,0],
}, {
duration:300,
complete: function() {
r5anim2();
}
});
}
var r5anim2 = function(){
$(".r5").velocity({
opacity: 0,
},{
duration:200,
complete: function() {
r6anim1();
wishes() // here i have called the function which should execute only on first loop.
}
});
}
var r6anim1 = function(){
$(".r6").velocity({
opacity: 1,
scale: [1,0],
}, {
duration:300,
complete: function() {
r6anim2();
}
});
}
var r6anim2 = function(){
$(".r6").velocity({
opacity: 0,
},{
duration:200,
complete: function() {
r5anim1(); //on end this will start the loop again
}
});
}
/*****************this function should be called only for the first time******************/
var wishes = function(){
boolvalue = 0;
$(".wishes").velocity({
opacity: 1,
scale: [1,0.4],
}, {
duration:600,
});
}
r5anim1();
【问题讨论】:
-
在循环外声明一个临时变量并设置默认为true,如果它的调用函数为true,则在循环中检查它一旦被调用的函数使其为false
标签: jquery velocity.js