javascript - 尝试在 JS 中进行星形旋转

标签 javascript range

我有以下代码片段,它尚未完成,目前只有右键起作用:https://jsfiddle.net/8ghey1oh/

我面临的问题如下。当我加载页面时,var rangeValue = document.querySelector(".rng").value;保持在 50。无论如何,我可以在移动范围 slider 时改变它吗?

另一件事是,如果我按下右侧按钮,它会播放动画,但如果我再次按下它,它就不会播放。

感谢您的帮助。

最佳答案

对于第一个问题,只需在调用 rotateRight 时读取值,而不是在加载时读取值。

对于第二个问题,解决方案是使用 animationend 完成动画后重置动画(请参阅 Using CSS animations )。

var rightBtn = document.querySelector(".btnRight");
var star = document.querySelector(".starWrap");
star.addEventListener('animationend', function() {
    this.style.animation = "none";
});

function rotateRight(){
  var rangeValue = document.querySelector(".rng").value;
  var getSeconds = Math.floor(rangeValue)/10;
  star.style.animation = "spin linear "+getSeconds.toString()+"s";
}

rightBtn.addEventListener("click", rotateRight);

fiddle :https://jsfiddle.net/qxuthk1z/

关于javascript - 尝试在 JS 中进行星形旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40158887/

相关文章:

python - 打印号码和号码列表的执行时间

javascript - 在react中使用map函数时如何使用if语句插入索引?

javascript - 使用 angularjs 自动创建行时数据不显示

python - 从 Python 列表中获取数据范围

python - 将所有子图的 yaxis 设置为相同的范围 - Matplotlib

python - 在 python range() 中是否有类似除以或乘以的方法?

JavaScript 超时

javascript - jQuery dragenter 或 dragover 以包含子项

javascript - 在 JavaScript 中重新加载页面

jQuery-UI 日期和时间范围选择器