[英]why does my JS code runs only once?
Here's my question: 这是我的问题:
I have an script tag at the end of my document, with this: 我在文档的末尾有一个脚本标签,其中包括:
<script>
$("#one").css("height",$("#two").width()/2);
</script>
And I want it to keep refreshing the code... But it only runs when I refresh the page. 而且我希望它继续刷新代码...但是它仅在刷新页面时运行。 What should I do to keep running it? 我应该怎么做才能继续运行?
<script>
setInterval(function() {
$("#one").css("height",$("#two").width()/2);
}, 1000);
</script>
This will repeat the function every 1000ms (=1s). 这将每1000ms(= 1s)重复一次功能。
If this is to animate something you can use the jquery .animate 如果这是要进行动画处理,则可以使用jquery .animate
$("#one").animate({height:0},1000);
this animates the height down to 0 and doing so over 1000 ms. 这会将动画高度降低到0,并超过1000毫秒。 there is plenty of other options with it. 还有很多其他选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.