我试图在执行jQuery animate属性的过程中暂停它。
下面的代码随机暂停,然后在动画中间播放动画。
我希望用一个更简单的序列来实现这一点,比如设置marginLeft的动画,随机暂停半秒或整秒,然后在var$play处执行动画停止的拾取。
我试图放慢整个动画的速度,随机添加停止点,然后尝试拾取原始动画序列。
如有任何帮助,我们将不胜感激。
<script>
$(document).ready(function() {
var $block = $('.1');
var numRand1 = Math.floor(Math.random()*4000)
var numRand2 = Math.floor(Math.random()*3000)
var numRand3 = Math.floor(Math.random()*9000)
var $play = $block.animate({"marginLeft": "420px"}, numRand1);
setInterval(function() {
$block.stop();
$block.delay(1500);
$block.animate({"marginLeft": "420px"}, numRand2);
}, 2000);
setInterval(function() {
$block.stop();
$block.delay(2500);
$block.animate({"marginLeft": "420px"}, numRand3);
}, 4000);
});
</script>
<style>
.block{
width:50px;
height:50px;
background:#ff0000;
margin-bottom:20px;
}
</style>
<div class="block 1"></div>
尝试以下链接:
http://jsfiddle.net/bTYb8/1/
编辑:
我已经在下面的链接中重置了你的例子,但它似乎有效,所以我不确定你希望它以什么方式表现不同
http://jsfiddle.net/bs32V/2/
尝试以下操作:
$("#block").animate({"marginLeft": "400px"}, "10000").delay(30).animate({"marginLeft": "800px"}, "10000");
..