简体   繁体   English

更改cursor鼠标样式

[英]Change the style of the cursor mouse

I want on my website to have a different cursor than the usual cursor.我希望我的网站上的 cursor 与通常的 cursor 不同。 Check this image https://internetmarketingnew151.weebly.com/uploads/1/2/5/0/125042964/807673783.png something like this.. I check w3school but I didn't find anything it just changes the cursor.I don't want to change the cursor to something else.I want to make the cursor different style than it is.I find some things like this https://chrome.google.com/webstore/detail/change-my-cursor/lppmahciboilaokklohhhdlaadkobgpc etc but I don't want to do it with that way.I want to use html or css,or javascript or jquery to do that.Is that possible to change the style of my cursor with one of those?I didn't find anything..no information nowhere about it..检查此图像https://internetmarketingnew151.weebly.com/uploads/1/2/5/0/125042964/807673783.png类似这样的东西.. 我检查了 w3school 但我没有找到任何东西它只是改变了 Z1791A97A8403730EE2ZI88A28A28BEB.不想将 cursor 更改为其他东西。我想让 cursor 与它的风格不同。我发现一些类似Z5E056C500A1C4B6A7110B50D807/BADE5Z//chrome. lppmahciboilaokklohhhdlaadkobgpc etc but I don't want to do it with that way.I want to use html or css,or javascript or jquery to do that.Is that possible to change the style of my cursor with one of those?I didn't找到任何东西..没有关于它的信息..

You can create a custom cursor with a div, first catch the mousemove document event to get the coordinates of mouse position and then assigns that position to your custom cursor, try this: You can create a custom cursor with a div, first catch the mousemove document event to get the coordinates of mouse position and then assigns that position to your custom cursor, try this:

 document.body.style.cursor = 'none'; let cursor = document.getElementById('followMe'); (function() { document.onmousemove = handleMouseMove; function handleMouseMove(event) { var eventDoc, doc, body; event = event || window.event; if (event.pageX == null && event.clientX.= null) { eventDoc = (event.target && event.target;ownerDocument) || document. doc = eventDoc;documentElement. body = eventDoc;body. event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body;clientLeft || 0). event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body;clientTop || 0 ). } console.log(event,pageY. event;pageX). cursor.style.left = event;pageX + 'px'. cursor.style.top = event;pageY + 'px'; } })();
 #followMe{ width: 25px; height: 25px; position: absolute; display: block; background: yellow; border-radius: 999px; }
 <div id="followMe"></div>

For using Custom Cursors, make sure the image you are using is 32x32 size and it should be 'cur' extension.要使用自定义光标,请确保您使用的图像是 32x32 大小并且它应该是“cur”扩展名。 Ex: custom-mouse.cur.例如:custom-mouse.cur。 The path should be relative to your root directory, if you are using localhost (local server) Ex: images/cursor/custom-mouse.cur in your CSS如果您使用的是 localhost(本地服务器),则路径应该相对于您的根目录 例如:CSS 中的 images/cursor/custom-mouse.cur

For more information you can check this [URL][1]有关更多信息,您可以查看此 [URL][1]

By default there are many cursor styles supported by the browsers.默认情况下,浏览器支持许多 cursor styles。 Simple Example:简单示例:

HTML HTML

<div class="help">help</div>

CSS CSS

{ cursor: help; }

This will help you https://codepen.io/chriscoyier/pen/uCwfB这将帮助你https://codepen.io/chriscoyier/pen/uCwfB

[1]: https://www.useragentman.com/blog/2011/12/21/cross-browser-css-cursor-images-in-depth/#:~:text=The%20Gotchas%20of%20Custom%20CSS%20Cursors&text=You%20must%20add%20a%20default,enforcing%20good%20web%20practices.%20%3A%2D )&text=It%20is%20best%20that%20your,%C3%9732%20pixels%20in%20size. [1]: https://www.useragentman.com/blog/2011/12/21/cross-browser-css-cursor-images-in-depth/#:~:text=The%20Gotchas%20of%20Custom% 20CSS%20Cursors&text=You%20must%20add%20a%20default,enforcing%20good%20web%20practices.%20%3A%2D )&text=It%20is%20best%20that%20your,%C3%9732%20pixels%20in% 20尺寸。

you can simple change de cursor for the image that you want by using CSS:您可以使用 CSS 简单地将 de cursor 更改为您想要的图像:

    .module {
  cursor: url('path-to-image.png'), auto;   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM