Mouse cursor not changing if a pointer is not moved in Webkit-based browsers

前端 未结 4 2181
梦毁少年i
梦毁少年i 2020-12-20 15:47

Let\'s assume that we have simple jQuery code like the following:

var $document = $(document);
$document.ready(function() {
    var $test = $(\"#test\");
            


        
4条回答
  •  被撕碎了的回忆
    2020-12-20 16:03

    Contrary to what was said before, this workaround I found from David Becker seems to be effective. (The fixes for the browsers are in the pipe. See https://bugs.webkit.org/show_bug.cgi?id=101857 )

    function _repaintCursor() {
        var saveCursor = document.body.style.cursor,
            newCursor = saveCursor ? "" : "wait";
        _setCursor(newCursor);
        _setCursor(saveCursor);
    }
    
    function _setCursor(cursor) {
        var wkch = document.createElement("div");
        var wkch2 = document.createElement("div");
        wkch.style.overflow = "hidden";
        wkch.style.position = "absolute";
        wkch.style.left = "0px";
        wkch.style.top = "0px";
        wkch.style.width = "100%";
        wkch.style.height = "100%";
        wkch2.style.width = "200%";
        wkch2.style.height = "200%";
        wkch.appendChild(wkch2);
        document.body.appendChild(wkch);
        document.body.style.cursor = cursor;
        wkch.scrollLeft = 1;
        wkch.scrollLeft = 0;
        document.body.removeChild(wkch);
    }
    

提交回复
热议问题