代码示例:
<body>
<div id="something" style="width: 50vw; height: 300px;">
</div>
<div class="else">oekdoekod</div>
</body>
问题是我只需要在悬停 body 时才需要有光标指针效果,而不是将 id="something"
悬停在 div
上。
没用
:not(#something) {
cursor: pointer;
}
但是
$(document.body).on("hover", ":not(#something, #something *)",function(e){
$(this).addClass("pointer");
e.stopPropagation();
});
使用 CSS
.pointer {
cursor: pointer;
}
它有效,但仅适用于其他元素,例如.else
如何将 pointer
光标应用到 hover
事件上,但只在 body 上而不是在 #something
上?
最佳答案
这对我有用,你在什么浏览器中测试它?这是 JSBin .
CSS
body{
cursor:crosshair;
}
#something {
width: 50vw;
height: 300px;
background-color:rgba(0,0,255,.2);
cursor:pointer;
}
#else{
width: 50vw;
height: 300px;
background-color:rgba(0,255,255,.2);
}
html
<div id="something"></div>
<div id="else"></div>
关于jquery - 将悬停事件(光标指针属性)添加到主体而不是其子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29233201/