javascript - Javascript 动画在 Safari 14 中无法正常工作
问题描述
对于投资组合网站,我使用的是我在这里找到的代码片段,一种 DVD 动画。由于我在 Mac OS Big Sur 上安装了 Safari 14,因此动画无法正常工作。它似乎在它的运动中留下了一些痕迹。有人知道这个问题吗?我该如何解决?非常感谢。
这是 Chrome 上 的屏幕截图 这是 Safari 14 上的屏幕截图
这是我的动画js:
//Constants
const section = document.getElementById("anim_jtm");
const logo = document.getElementById("logo");
const body = document.getElementById("body");
section.style.height = body.clientHeight + "px";
section.style.width = body.clientWidth + "px";
// Logo moving velocity Variables
let xPosition = 10;
let yPosition = 10;
let xSpeed = 0.7;
let ySpeed = 0.7;
function update() {
logo.style.left = xPosition + "px";
logo.style.top = yPosition + "px";
}
setInterval(() => {
if (xPosition + logo.clientWidth >= body.clientWidth || xPosition <= 0) {
xSpeed = -xSpeed;
logo.style.fill = randomColor();
}
if (yPosition + logo.clientHeight >= body.clientHeight || yPosition <= 0) {
ySpeed = -ySpeed;
logo.style.fill = randomColor();
}
xPosition += xSpeed;
yPosition += ySpeed;
update();
}, 1);
function randomColor() {
let color = "#";
color += Math.random().toString(16).slice(2, 8).toUpperCase();
return color;
}
window.addEventListener("resize", () => {
xPosition = 10;
yPosition = 10;
section.style.height = body.clientHeight + "px";
section.style.width = body.clientWidth + "px";
});
解决方案
推荐阅读
- java - 无法从 java spring api 获取资源,可能是 jpa 故障
- logging - DI ILogger的正确方法
在派生类中 - azure - Azure 文件共享路径与使用 ARM 模板的容器实例卷路径映射
- wso2 - 如何获取 wso2 esb 代理参数
- linux - ssh_exchange_identification:远程主机linux服务器关闭到Mac机器的连接
- authentication - Azure SQL DB - 如何创建新的登录名、访问受限的用户?
- opam - 如何在旧的不可用版本中安装 opam 包?
- r - R(RStudio)控制台编码问题
- python - 导入“embed_video.fields”无法解析 Pylance 报告缺少导入
- loops - 在批处理文件的 for 循环中设置随机变量值会产生错误