我有一个在悬停按钮时移动框的功能。只要鼠标悬停在按钮上,我希望该功能每秒一遍又一遍地运行。我也尝试过循环,但我无法让它工作。如果您能对此进行调查,我将不胜感激。这是我的代码:
<!DOCTYPE html>
<head>
<style>
#box {
position: relative;
top: 20px;
left: 10px;
width: 50px;
height: 50px;
background:#333366;
}
</style>
<script>
function Start() {
setInterval(Move('box'),1000);
}
var value = 0;
function Move(element) {
value += 50;
var box = document.getElementById(element);
box.style.transition = "left 0.2s ease-in-out 0s";
box.style.left = value+'px';
}
</script>
</head>
<body>
<button onmouseover="Start();">Hover to move</button>
<div id="box"></div>
</body>
</html>