javascript - Javascript 动画。在点之间悬停时移动 div
问题描述
我需要在悬停时在闪光灯周围移动红色圆圈,但是当光标消失时,它会回到起点。我怎样才能在循环中暂停?也许是做这个动画的另一种方式?
var circle = document.querySelector('.circle');
var wayPoints = [[32.3,23.3],[42,42],[45.5,36.5],[55.2,53.7],[57.8,49.2],[73.5,78.5],[52.5,61],[50.5,65.5],[39,52],[36.5,56],[22.5,44.8]];
circle.addEventListener('mouseover', moveCircle);
//circle.addEventListener('mouseout', backCircle);
function moveCircle(){
for(i in wayPoints){
circle.style.top = wayPoints[i][0];
circle.style.left = wayPoints[i][1];
}
}
body{
height: 100vh;
padding: 0;
margin:0;
display: flex;
justify-content: center;
align-items: center;
}
.animation_wrapper{
width: 80%;
height: auto;
border: 2px solid black;
position: relative;
}
.circle{
width: 2%;
height: 4%;
border-radius: 50%;
background: red;
position: absolute;
top: 32.3%;
left:23.3%;
cursor: pointer;
transition: 4s;
}
img{
width: 100%;
}
<div class="animation_wrapper">
<img src="https://i.pinimg.com/originals/26/41/a9/2641a94b84a88671449faea04d29a647.png" alt="flash">
<div class="circle"></div>
</div>
这是我在stackoverflow上的第一次体验,所以你也可以给一些写问题的建议:)谢谢你的帮助!
解决方案
推荐阅读
- c# - 实体框架 SqlQuery 可空字段
- javascript - 如何使用 javascript 从 firefox 页面获取表数据
- java - 图像未显示在 Firebase RecyclerView 中
- ms-access - 在 Access 2010 中过滤第三个位置的 mid 函数
- nim-lang - Nim 在内存效率方面与 Java 相似吗?
- windows-installer - log4net 日志文件在应用程序安装子文件夹的 Windows 资源管理器中不可见
- angular - 如何通过 Angular ViewChildren 访问 SVG 元素
- python - Python 3.x:将两个具有相同键和值的字典合并为数组
- php - str_replace 以 x 开头并以 x 结尾的值
- javascript - 将js变量发送到mvc控制器