admin管理员组文章数量:1334918
i want to disable click function untill every code in it; initialized and pleted.
i read these articles and tried what they said but cant make it happen: event.preventDefault() vs. return false + Best way to remove an event handler in jQuery? + jQuery - Disable Click until all chained animations are plete
i prepared simple example for this question:
This is DEMO
html
<div class="ele">1</div>
<div class="ele">2</div>
<div class="ele">3</div>
jQuery
$('.ele').click(function() {
if ( !$('.ele').is(':animated') ) {//this works too but;
//is:animate duration returns = 2000 but need to be 4000
$('.ele').stop().animate({'top':'0px'},2000);
$(this).stop().animate({'top':'100px'},4000);
}
return false;
});
i want to disable click function untill every code in it; initialized and pleted.
i read these articles and tried what they said but cant make it happen: event.preventDefault() vs. return false + Best way to remove an event handler in jQuery? + jQuery - Disable Click until all chained animations are plete
i prepared simple example for this question:
This is DEMO
html
<div class="ele">1</div>
<div class="ele">2</div>
<div class="ele">3</div>
jQuery
$('.ele').click(function() {
if ( !$('.ele').is(':animated') ) {//this works too but;
//is:animate duration returns = 2000 but need to be 4000
$('.ele').stop().animate({'top':'0px'},2000);
$(this).stop().animate({'top':'100px'},4000);
}
return false;
});
Share
Improve this question
edited May 23, 2017 at 12:07
CommunityBot
11 silver badge
asked Jul 1, 2012 at 15:40
Barlas ApaydinBarlas Apaydin
7,31511 gold badges58 silver badges88 bronze badges
2 Answers
Reset to default 5Use on() and off() to turn the click function on/off :
$('.ele').on('click', animateEle);
function animateEle(e) {
$('.ele').stop().animate({'top':'0px'},2000);
$(e.target).off('click').stop().animate({'top':'100px'},4000, function() {
$(e.target).on('click', animateEle);
});
}
DEMONSTRATION
You can try this:
var exec_a1 = true, exec_a2 = true;
$('.ele').click(function() {
if (exec_a1 && exec_a2) {
exec_a1 = false;
exec_a2 = false;
$('.ele').stop().animate({'top': '0px'}, 2000, function() {
exec_a1 = true;
});
$(this).stop().animate({'top': '100px'}, 4000, function() {
exec_a2 = true;
});
}
return false;
});
本文标签: javascriptjquery disable click until animation is fully completeStack Overflow
版权声明:本文标题:javascript - jquery disable click until animation is fully complete - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742325052a2453557.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论