我正在尝试相对于其他一些 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 中明确设置的。
关于javascript - 为什么 anime.js 不为 Firefox 或 Microsoft Edge 中的左侧属性设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56704281/