猿问

为什么window.setInterval(step,1000);还是只执行一次?

<script>


var time;

window.onload=function(){

    var oHeart=document.querySelector(".heart");


    function step(){

        oHeart.style.transform="scale(0.7)";

    }

    这里使用的是step不是step();为什么还是只执行一次?

 time= window.setInterval(step,1000);

    


}

</script>


慕码人8056858
浏览 1231回答 2
2回答

吃鸡游戏

var time;window.onload=function(){&nbsp; &nbsp; var oHeart=document.querySelector(".heart");&nbsp; &nbsp; function step(){&nbsp; &nbsp; &nbsp; &nbsp; oHeart.style.transform="scale(0.7)";&nbsp; &nbsp; }&nbsp; &nbsp; 这里使用的是step不是step();为什么还是只执行一次?&nbsp;time= window.setInterval(step,1000);&nbsp; &nbsp;}每秒都执行,不过每秒钟都设置缩放比例0.7,肉眼看不出而已,你可以打console

喵喔喔

并不是只执行一次,是你前后的style没变化,你看不出来而已,试试这个var time;window.onload = function(){&nbsp; &nbsp; let oHeart = document.querySelector(".heart");&nbsp; &nbsp; function step(){&nbsp; &nbsp; &nbsp; &nbsp; oHeart.style.transform = "scale(1.0)";&nbsp; &nbsp; &nbsp; &nbsp; setTimeout(() => oHeart.style.transform="scale(0.7)", 500);&nbsp; &nbsp; }&nbsp; &nbsp; time = window.setInterval(step,1000);&nbsp; &nbsp;&nbsp;}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答