我有一個拖動UI程序,其中可拖動元素上的鼠標光標變爲點擊抓取手。更改整個頁面的鼠標光標?
的問題是,我讓拖動到屏幕上的任何地方發生,並在錨標記,等光標變爲...
我試過$('*').addClass('grabbing')
,但它真的很貴。
有沒有簡單易用的代碼處理方法?
我有一個拖動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是上,您可以看到在機身風格標籤的變化。但有些如何不起作用。你可以把它作爲參考,並嘗試類似的方法獲得解決方案。
不會僱用zIndex的元素重寫? –
@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 –