[英]How to change the mouse pointer to the image that was clicked on in Javascript
[英]How to change the mouse pointer?
我需要將鼠標指針更改為等待光標。 我試過了
document.body.style.cursor = 'wait';
在我的小提琴中 ,鼠標光標沒有改變(在主應用程序中也沒有改變)。 我嘗試了幾種方法,但似乎沒有任何效果(已測試IE7和FF7)。 如何更改光標? 如果效果更好,我願意使用CSS而不是JavaScript。
為了它的價值...在最終程序中,我需要在AJAX調用開始時更改指針,然后在回調中將其更改回默認值。 但是,這是一個簡化的示例,仍然無法正常工作。
我將創建一個CSS類:
.busy {
cursor: wait !important;
}
然后將此類分配給body或要標記為忙的任何元素:
$('body').addClass('busy');
// or, if you do not use jQuery:
document.body.className += ' busy';
http://jsfiddle.net/ThiefMaster/S7wza/
如果整個頁面都需要它,請參閱在整個html頁面上等待光標以獲取解決方案
由於沒有文本,因此您實際上沒有身體(就“它沒有高度”而言)。
嘗試添加一些內容,然后將文本懸停在http://jsfiddle.net/kX4Es/4/上 。 您可以只使用CSS。
或者,將其添加到<html>
元素以繞過此<body>
約束: http : //jsfiddle.net/kX4Es/3/ 。
html {
cursor: wait;
}
您是否在聲明它為功能?
function cursor_wait() {
document.body.style.cursor = 'wait';
}
然后打電話
cursor_wait();
在您的腳本中?
像這樣:
$('html').css('cursor', 'wait');
或者作為ThiefMaster上面所說的CSS類
我只在chrome和firefox中嘗試過此功能,因此它可能無法在所有地方使用。 但是,如果您要使用javascript並打開和關閉它,請嘗試此操作。
//add
document.styleSheets[1].insertRule('html {cursor:wait;}',document.styleSheets[1].cssRules.length);
//for firefox I had to tell it to fill the screen with the html element
//document.styleSheets[1].insertRule('html {height:100%;width:100%;cursor:wait;}',0);
//remove
document.styleSheets[1].deleteRule(document.styleSheets[1].cssRules.length-1);
http://www.quirksmode.org/dom/w3c_css.html#access似乎是弄亂實際樣式表的很好參考。 我希望找到一種更好的方法來編輯html元素樣式,但這就是我所能找到的全部...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.