作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想检测鼠标何时离开顶部的视口(viewport)(可以说是向北)。我在网上搜了下How can I detect when the mouse leaves the window? .是一个好的开始,但它也会检测鼠标何时离开其他方向。我怎么能只检测到顶部的导出?
谢谢!
最佳答案
为了在不考虑滚动条和自动完成字段的情况下检测鼠标离开:
document.addEventListener("mouseleave", function(event){
if(event.clientY <= 0 || event.clientX <= 0 || (event.clientX >= window.innerWidth || event.clientY >= window.innerHeight))
{
console.log("I'm out");
}
});
然后你只需要删除条件:
event.clientY <= 0 is when the mouse leave from the top
event.clientX <= 0 is when the mouse leave from the left
event.clientX >= window.innerWidth is when the mouse leave from the right
event.clientY >= window.innerHeight is when the mouse leave from the bottom
关于viewport - 检测鼠标何时离开视口(viewport)顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26123916/
我正在尝试获得一个按钮,按下该按钮时会改变颜色。当再次按下时,它应该变回原来的颜色。我究竟做错了什么? 我的模板中的按钮: export default { data: {
我是一名优秀的程序员,十分优秀!