题解 | #控制动画#

控制动画

https://www.nowcoder.com/practice/5cc9c7c7021c4206ac825fda21d6a4bb

思路:使用animation设置动画,使用rect.style.animationDuration设置动画持续时间(注意单位是s)。

<style type="text/css">
   #rect {
     width: 120px;
     height: 100px;
     background-color: black;
     animation:rect 10s
   }
   @keyframes rect {
      from {
         transform: rotate(0deg);
      }
      to {
         transform: rotate(360deg);
      }
   }
</style>
<body>
 <div id="rect"></div>
 <input id="range" type="range" min="1" max="10" value="1" step="1"/> 
 <script type="text/javascript">      
    let input=document.getElementById("range")
    input.onchange=function(){
       let rect=document.getElementById("rect")
       let speed=this.value
       rect.style.animationDuration=11-speed+'s'
    }
</script>

总结:使用animation设置动画,使用rect.style.animationDuration设置动画持续时间(注意单位是s)。表示范围的input框是type为range,min为最小值,max是最大值,step是间隔,注意属性均是字符串。

#控制动画#
前端js面试 文章被收录于专栏

前端js面试,帮助你更好的理解js。

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-17 14:06
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务