我想用jQuery構建一個異步應用程序。最近我學習了一些關於setInterval如何對函數進行常量調用的概念,而其他函數中的邏輯在未準備好時保護活動。我所展示的代碼僅僅是我想要做的粗略草稿,而不是工作副本。我的問題是,我似乎無法創建邏輯,無限期地暫停動畫的一部分,然後恢復(準備好)其餘部分。我想我問你如何在動畫回調函數中創建邏輯?由於如何在jQuery動畫回調函數中創建邏輯?
var runAnimation;
var timePassed;
var someThing;
$(document).ready(function(){
asyncFunction();
});
function asyncFunction() {
if (someCondition == true) {
animationFunction(){
}
}
runAnimation = setInterval(animationConditions, 100)
}
function animationConditions(){
if (timePassed = 30) {
if( someThing == true) {
animationFunction() {
}
}
timePassed += 1;
}
function animationFunction() {
$('#show div')
.animate({left: 500},1500)
.delay(3000)
.queue(function(){
someThing = false;
//but in this section I would like something like a mouseover or
//other things to be able to pause the animation. I was experimenting
//with queue and dequeue but any time I use dequeue in this section
//it turns of the queue, even if the statement fails. For exmaple if it
//is in an else and the if is true. I would like to be able to add more
//pause on an event like a mouseover. When mouse leaves resume the animation.
//if(something == true){
// pause aniamtion indefinitely;
//}
}).dequeue().animate({left: 1100},1500);
}
在試圖弄明白我想出了這個
function animatePause(query, duration, distance){
checkAp = setInterval(function(){
if(marqueeVars.autoPlay == false) {
console.log("that's one");
query.delay(70000000000000000).animate({left: distance},function(){
clearInterval(checkAp);
console.log("long wait!");
});
} else {
console.log("that's two");
//console.log(query.html());
//clearInterval(checkAp);
query.delay(duration).animate({left: distance},function(){
clearInterval(checkAp);
console.log("regular wait!");
animateOut(query,1100);
});
}
}, 100);
}
我不明白,爲什麼裏面的代碼,如果()不執行?它從不清除間隔,它從不運行動畫?它似乎被忽略。我想我應該理解這個概念,甚至認爲我會看看插件。謝謝
哇,這是第二次被提到,我要檢查呃GreenSock pulgin。謝謝 – bistel
雖然試圖找到一種方式,我想出了這個: – bistel
我想你錯過了添加鏈接到您的評論...無論如何,讓我知道它是如何去。這很容易理解 –