在所有页面上隐藏光标(即使在某个元素上有一个css另有说明)



我正在尝试应用一个javascript代码,该代码应使用document.body.style.cursor = 'none';使光标在整个网页上不可见

但是当页面中有其他具有特定样式的元素时或者正在应用css类(将光标设置为特定值(鼠标悬停在这些元素上使光标可见。

下面是一个有我问题的html页面的例子:

<html>
<head>
<style>
pointerCursor {
cursor: "pointer"; 
}
</style>
</head>
<body>
<h1> here is a web page </h1>
<button class="pointerCursor">click me</button>
</body>
</html>

应用此代码时document.body.style.cursor = 'none';鼠标未隐藏在按钮上

感谢

您可以添加一个固定位置的div,覆盖您的网站。div的样式为cursor: none,由于它是一个覆盖层,它下面元素的样式不会触发光标更改

const overlay = document.createElement('div');
overlay.classList.add('overlay');
document.body.insertAdjacentElement('beforeend', overlay);
.overlay {
position: fixed;
cursor: none;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.pointerCursor {
cursor: "pointer";
}
<html>
<body>
<h1> here is a web page </h1>
<button class="pointerCursor">click me</button>
</body>
</html>

这可以通过添加和删除覆盖分区来切换。

注意:这将禁用按钮等输入(因为将单击覆盖而不是输入(。但不完全确定这是否是被通缉的行为。

给你,抱歉先误解了。

* {
cursor: none !important;
}
a {
cursor: pointer;
}
a.show {
padding-left: 1rem;
cursor: pointer !important;
}
<a href="#">Example link</a>
<a class="show" href="#">Example link</a>

不确定它是否算tho,因为您请求了JS解决方案。希望它对你有帮助!

相关内容

最新更新