javascript - 为什么anime.js 不为Firefox 或Microsoft Edge 中的left 属性设置动画?
问题描述
我正在尝试相对于其他一些 div 动态地为样式化 div 设置动画,这些 div 的数量和位置仅在运行时才知道。
以下 SSCCE 在 Chrome 中完美运行,但在 Firefox 或 Edge 中根本无法运行。有谁知道为什么?
我已经查看了许多其他类似的问题,但没有运气,并且说anime.js 文档很少是礼貌的。
import anime from "./anime.es.js";
var pips = document.getElementsByClassName("pip");
var fill = document.querySelector(".pip-fill");
var pipBorder = parseInt(window.getComputedStyle(pips[0]).borderWidth);
fill.style.left = (pips[0].offsetLeft + pipBorder) + "px";
fill.style.top = (pips[0].offsetTop + pipBorder) + "px";
anime({
targets: fill,
left: (pips[2].offsetLeft + pipBorder) + "px",
duration: 1000,
delay: 1000
});
.container {
position: relative;
}
.pip {
display: inline-block;
width: 32px;
height: 32px;
border-style: solid;
border-radius: 100%;
border-width: 4px;
border-color: black;
margin: 64px;
background-color: red;
}
.pip-fill {
position: absolute;
width: 32px;
height: 32px;
border-style: none;
border-radius: 100%;
background-color: black;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="./index.css"/>
</head>
<body>
<div class="container">
<div class="pip"></div>
<div class="pip"></div>
<div class="pip"></div>
<div class="pip-fill"></div>
</div>
<script src="./index.js" type="module"></script>
</body>
</html>
解决方案
这是一个奇怪的,但可能会帮助别人。我通过目标 div 的边框宽度来偏移填充 div 的位置。由于某种原因,在 Firefox 和 Edge 中window.getComputedStyle(pips[0]).borderWidth
都返回NaN
但window.getComputedStyle(pips[0]).borderTopWidth
返回正确的值。我认为这可能是一个错误,因为border-width
在 CSS 中明确设置。
推荐阅读
- python-3.x - 如何使用 python scrapy 单击按钮并从网站上抓取文本
- python - 在python中将两个连续的行合并为一个具有相同唯一键的行
- php - 变量不起作用的 fsockopen
- mysql - 设置为 NULL 的外键约束字段不起作用
- javascript - 打字稿:如何从对象中获取属性子集?
- c# - Json newtonsoft:从对象反序列化字符串数组
- gun - 如何建立一个有枪的作家群
- hadoop - 当从 hive 中的表中运行查询 select count(*) Map 任务正在完成但减速器任务未完成
- c - 如何修改以下代码以在 Matlab r2018a 上运行?
- java - slf4j 禁用调试垃圾邮件