javascript - 为什么 anime.js 不为 Firefox 或 Microsoft Edge 中的左侧属性设置动画?

标签 javascript css firefox microsoft-edge anime.js

我正在尝试相对于其他一些 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 返回 NaNwindow.getComputedStyle(pips[0]) .borderTopWidth 返回正确的值。我认为这可能是一个错误,因为 border-width 是在 CSS 中明确设置的。

关于javascript - 为什么 anime.js 不为 Firefox 或 Microsoft Edge 中的左侧属性设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56704281/

相关文章:

javascript - 为什么不调用 Kendo 数据源函数?

javascript - 如何保存cookies

html - CSS 将元素填充到网格中(并将它们居中)

javascript - 如何在不覆盖其下的元素的情况下旋转元素?

javascript - JS 关闭窗口

用于Firefox扩展的python?

javascript - <video> 使用 MediaRecorder() 从 <canvas> 播放录制的流,使用 canvas.captureStream() 在 firefox、chromium 上呈现不同的效果

javascript - 如何使用 javascript 写入 "on form submit complete"?

javascript - 将自动完成框大小与输入字段宽度分离

javascript - 如何在中心模式下创建 Slick Slider JS 幻灯片