[英]The bounce effect in jquery is not working ideally
I want create element which will appear with bounce effect and this effect should run all time while user not clicking to help_man
, when its happened effect is completed. 我想要创建带有反弹效果的元素,并且该效果应在用户未单击
help_man
所有时间运行,直到其发生的效果完成。 Now its work, but not prefer, effect run slow and eventually faster and faster. 现在,它的工作(但不是首选)的效果运行缓慢,最终越来越快。 Bounce does not always stop on mouse click event.
跳动并不总是在鼠标单击事件时停止。 JsFiddle HTML:
JsFiddle HTML:
<div class='task_wrapper'>
<div class='help_man'>
<img src='images/cow.png'/>
</div>
</div>
JS: JS:
<script src="js/jquery-ui-bounce.min.js"></script>
<script>
var to_stop = 0;
function run_bounce()
{
if(to_stop==0)
{
$(".task_wrapper").effect( "bounce", "fast" );
setInterval(run_bounce,3000);
}else{
return;
}
}
$(document).ready(function(){
$(".help_man").click(function() {
to_stop = 1;
});
run_bounce();
});
</script>
Thanks! 谢谢!
You need to add positon as abosulte in CSS.That is way we animate DOM elements on fly. 您需要在CSS中添加positon作为正式版本,这是我们动态制作DOM元素的方式。 Alway best pratices to
clearInterval
before call setInterVal(); 始终最好在调用setInterVal()之前先清除
clearInterval
; which return number. 哪个返回号码。
.task_wrapper{
postion:absolute;
}
var to_stop = 0,interval;
function run_bounce()
{
if(to_stop==0)
{
$(".task_wrapper").effect( "bounce", "fast" );
clearInterval(interval);
interval = setInterval(run_bounce,3000);
setInterval(run_bounce,3000);
}else{
$(".task_wrapper").stop(); //Note here stop()
}
}
$(document).ready(function(){
$(".help_man").click(function() {
to_stop = 1;
});
run_bounce();
});
I think you need to clear the interval, 我认为您需要清除间隔,
Fiddle: http://jsfiddle.net/9nEne/13/ 小提琴: http : //jsfiddle.net/9nEne/13/
JS JS
var to_stop = 0, interval;
function run_bounce() {
if(to_stop==0)
{
$(".task_wrapper").effect( "bounce", "fast" );
clearInterval(interval);
console.log(interval);
interval = setInterval(run_bounce,3000);
}else{
$(".task_wrapper").stop();
}
}
$(document).ready(function(){
$(".help_man").click(function() {
to_stop = 1;
});
run_bounce();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.