更改整个页面的鼠标光标?
问题描述:
我有一个拖动UI程序,其中可拖动元素上的鼠标光标变为点击抓取手。更改整个页面的鼠标光标?
的问题是,我让拖动到屏幕上的任何地方发生,并在锚标记,等光标变为...
我试过$('*').addClass('grabbing')
,但它真的很贵。
有没有简单易用的代码处理方法?
答
试试这个
$('body').addClass('grabbing');
OR
$(document).addClass('grabbing');
// EDITED ANSWER
$('body').mousedown(function(e){
$(this).css({'cursor':'pointer'});
}).mouseup(function(e){
$(this).css({'cursor':'auto'});
});
如果Firebug是上,您可以看到在机身风格标签的变化。但有些如何不起作用。你可以把它作为参考,并尝试类似的方法获得解决方案。
+0
不会雇用zIndex的元素重写? –
+0
@MikeChristensen正确。这不会做到这一点。 – Wesley
答
我能想到做到这一点的唯一方法是相当黑客。
创建一个D-Z,其索引高于该页面上所有内容的Z值,并且具有所需的光标。只要鼠标光标关闭,就启用该div。示例代码:
<html><body style="width: 100%; height: 100%;">
<DIV id="cover" style="position: absolute; width: 100%; height: 100%; zindex: 5000; top: 0px; left: 0px; cursor: pointer; background: transparent; display: none;"> </div>
<ul><li>One</li><li>Two</li><li>Three</li></ul>
<script>
window.document.body.onmousedown = function()
{
document.getElementById('cover').style.display = '';
};
window.document.body.onmouseup = function()
{
document.getElementById('cover').style.display = 'none';
};
</script>
</body></html>
参见:http://stackoverflow.com/questions/192900/wait-cursor-over-entire-html-page –