jquery - 将悬停事件(光标指针属性)添加到主体而不是其子项

标签 jquery css hover

代码示例:

<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/

相关文章:

php - jQuery:自动刷新 `<div>`

jquery - 带有 jquery 的 Django 模板 : Ajax update on existing page

php - 我试图用 PHP、MySQL、jQuery 和 css 处理的乱七八糟的事

jquery - 双圆圈按钮悬停

HTML、CSS 悬停在图像上

jquery - 有什么方法可以将一些 html/css 导出到图像吗?

jQuery 多次调用点击

html - CSS 不适用于类,但适用于 body 元素

html - 重叠 HTML 边框底部

php - jquery 在悬停时更改图像(然后返回初始图像)