JavaScript设置间隔不减少变量值 计数=25; setInterval(函数(){ document.getElementById(“rope”).style.webkittTransform=“rotate”(+count+“deg)”; 计数=计数*-1; 计数=计数-1; } ,'1000');
测试它,有一个问题:它永远不会减少它来回旋转的量 需要帮助,因为这应该很容易解决,但是setInterval总是设法让我难堪,尤其是在添加变量时:\JavaScript设置间隔不减少变量值 计数=25; setInterval(函数(){ document.getElementById(“rope”).style.webkittTransform=“rotate”(+count+“deg)”; 计数=计数*-1; 计数=计数-1; } ,'1000');,javascript,jquery,html,css,setinterval,Javascript,Jquery,Html,Css,Setinterval,测试它,有一个问题:它永远不会减少它来回旋转的量 需要帮助,因为这应该很容易解决,但是setInterval总是设法让我难堪,尤其是在添加变量时:\ 我希望它每次旋转的越来越少。。。非常感谢您的帮助:)您的问题是计数在-26和25之间跳跃 对于每个间隔: 计数=-计数-1=-26 计数=-(-26)-1=26-1=25 计数=-(25)-1=-26 计数= 所以计数将在这两个值之间反弹-26和25 根据您的评论,只需通过if测试(即if(count0) { count=count-4;//将4更
我希望它每次旋转的越来越少。。。非常感谢您的帮助:)您的问题是计数在-26和25之间跳跃 对于每个间隔:
根据您的评论,只需通过if测试(即if(count<0){…})来实现这一点 你的
count=count*-1代码>和<代码>计数=计数-1
只会重复-26和25的模式。解决方案JS
count=25;
intvar=setInterval(函数(){
document.getElementById(“rope”).style.webkittTransform=“旋转(“+count+”deg)”;
计数=计数*-1;
如果(计数>0)
{
count=count-4;//将4更改为任何小整数,以使每次角度行程的差值(以度为单位)尽可能小,如果希望每次角度行程的差值更大,则将其保持大。
如果(count25*-1-1==-26
-26*-1-1==25
那又怎么样?我想至少应该有一个数字的变化,即使他们加错了@fabriciomattéFabricio想说的是,在每一秒间隔后,数字会回到25。哦,是的。该死的,我是弱智(无意冒犯)…Sooo我如何检测数字是否为负数。好的…知道了:)Sooo我如何检测数字是否为负数。好的,知道了。这很有意义,我将执行if.:)if>0其他
<div id="rope" style="-webkit-transform: rotate(-25deg);-webkit-transition:all 1s;position:absolute;top:50px;left:50px;">
<div style="position:absolute;top:25px;left:25px;width:5px;background-color:#c3c3c3;height:100px;"></div>
<div style="position:absolute;top:100px;left:15px;"><img src="http://images1.wikia.nocookie.net/__cb20111028025351/cuttherope/images/1/1c/Candy.png" style="height:30px;"></div>
</div>
<script>
count = 25;
setInterval(function(){
document.getElementById("rope").style.webkitTransform="rotate("+count+"deg)";
count = count*-1;
count = count-1;
} ,'1000');
</script>
count = 25;
intvar=setInterval(function(){
document.getElementById("rope").style.webkitTransform = "rotate("+count+"deg)";
count = count*-1;
if(count>0)
{
count = count-4;// Change 4 to any small integer to keep the difference of angular travel(in degree) each time as small as possible and keep it big if you want a greater difference each time in the angular travel.
if(count<0)
clearInterval(intvar);
console.log(count);
}
} ,'1000');