javascript - 为什么我的 css3 动画在 chrome 和 edge 中如此错误?
问题描述
所以我一直在做一个网站,这是我第一次尝试网络开发。现在因为我通常使用 Firefox,所以我首先在 Firefox 上起草我的网站。现在我知道 Firefox 是 Gecko,Chrome 和 Edge 是 Webkit,因此它们之间可能存在一些差异。所有的动画和一切都在 Firefox 上表现得非常好——自定义光标、CSS 选框,几乎所有东西。我的代码写得那么糟糕,还是我做错了什么?
/*kinda laggy cursor control js */
const cursor = document.querySelector('.cursor');
document.addEventListener('mousemove', e => {
cursor.setAttribute("style", "top: " + e.pageY + "px; left: " + e.pageX + "px;")
})
const cursor2 = document.querySelector('.cursor2');
document.addEventListener('mousemove', e => {
cursor2.setAttribute("style", "top: " + e.pageY + "px; left: " + e.pageX + "px;")
})
const links = document.querySelectorAll('a')
links.forEach(link => {
link.addEventListener('mouseenter', e => {
cursor.classList.add('enlarged')
})
link.addEventListener('mouseout', e => {
cursor.classList.remove('enlarged')
})
})
const labels = document.querySelectorAll('label')
labels.forEach(label => {
label.addEventListener('mouseenter', e => {
cursor.classList.add('enlarged')
})
label.addEventListener('mouseout', e => {
cursor.classList.remove('enlarged')
})
})
.cursor {
width: 25px;
height: 25px;
position: absolute;
border: 2px solid rgb(83, 83, 83);
border-radius: 50%;
transform: translate(-50%, -50%);
transition: 50ms;
transition-timing-function: ease-out;
mix-blend-mode: exclusion;
z-index: 800;
pointer-events: none;
transition: color 100ms ease, top 50ms linear, left 50ms linear, width 500ms ease, height 500ms ease;
}
.cursor2 {
z-index: 800;
transition: 10ms;
width: 5px;
height: 5px;
border-radius: 50%;
background-color: rgb(83, 83, 83);
pointer-events: none;
mix-blend-mode: difference;
position: absolute;
}
body {
overflow: hidden;
font-size: 100%;
height: 100vh;
cursor: none;
}
<!-- outer cursor div-->
<div class="cursor">
</div>
<!-- inner cursor div-->
<div class="cursor2">
</div>
上面的代码片段是一个自定义光标,我遵循这个随机的 Youtube 教程。教程中的那个人得到了一个非常不错的光标,他似乎甚至在使用 chrome,光标工作得很好。然而,当我在 chrome 中运行我的代码时,我得到了一个疯狂的延迟,光标只是在整个地方传送。任何和所有 :hover 过渡都非常突然,而在 Firefox 中它似乎工作得很好。
解决方案
推荐阅读
- php - 如何正确获取特定大会的所有注册信息?
- python-3.x - 使用熊猫数据框或其他任何python 3将(列表)列表添加到csv
- pandas - 用 pandas 读取 csv 并指定列名
- java - 如果我每次都将一个新对象传递给一个方法,这是一种不好的做法,因为我分配了这么多可能不会使用的新对象?
- sql - 如何以字符串格式编写 SQL 命令
- github - 如何比较 GitHub 中的两个目录?
- javascript - 悬停时 JS 事件的 Refato 提示
- emacs - 循环软包裹的视觉线条
- ionic-framework - 重命名离子项目中的选项卡标题
- asp.net-mvc - 如何使用 mvc 在视图中将多个模型数据显示到单个 Html 表中