问题
I have the following CSS that hides the mouse cursor for anything on the web page. It works perfectly in Firefox, but in IE and Chrome, it doesn't work.
html {
cursor: none;
}
In Chrome, I always see the mouse pointer. In IE, however, I see whatever cursor was last 'active' when it entered the screen. Presumably it's keeping the last selection instead of removing it.
回答1:
This property cursor:none;
isn't part of the standard
See here w3c cursor CSS properties.
You might want to look into hiding it with Javascript or JQuery.
Also, look at blank cursor files here.
And one last link to an ajax solution.
Chrome has had this issue since it was built, there have been reports sent to the people at Chromium, and I assume they are working on it.
Also, don't trust that anything would work in IE. Ever. :P
回答2:
I had the same problem in these days and found a good solution to hide the pointer in Google Chrome.
This is the W3C definition of url property:
A comma separated of URLs to custom cursors. Note: Always specify a generic cursor at the end of the list, in case none of the URL-defined cursors can be used
So, you can define a url to not completely transparent image, followed by the default pointer:
cursor: url(img/almost_transparent.png), default;
If you choose a totally transparent png, Chrome will display a black rectangle instead, but if you choose a png with at least 1px not transparent it will work, and nobody will notice the pointer.
回答3:
Finding something that works across browsers is a pain.
The code below works on Chrome, IE, and Firefox. IE likes .cur files, Chrome likes the embedded png, and some browsers actually respect the none :)
div {
cursor: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjbQg61aAAAADUlEQVQYV2P4//8/IwAI/QL/+TZZdwAAAABJRU5ErkJggg=='),
url(images/blank.cur),
none;
}
回答4:
So the best way to deal with this now is the pointer lock api.
https://developer.mozilla.org/en-US/docs/WebAPI/Pointer_Lock
It'll hide the mouse cursor, but give you access to the data about mouse movement as well.
回答5:
In css: * { cursor: url(cursor.png), none !important }
回答6:
Use a hidden applet with the java.awt.robot class to move the cursor off the sreen. Say the very lower left corner.
来源:https://stackoverflow.com/questions/2636068/hide-cursor-in-chrome-and-ie