简体   繁体   English

如何在 JS 或 CSS 中使用 svg 作为鼠标光标?

[英]How use an svg as a mouse cursor in JS or CSS?

I'm having troubles while trying to make a svg being the cursor while hovering an image.在悬停图像时尝试将 svg 设为光标时遇到了麻烦。 Here's the example:这是示例:

<div class="main">
 <div class="image1"></div>
 <div class="image2"></div>
 <div class="image3"></div>
<svg class="arrowWrapper" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 270.7 166.49" xml:space="preserve"><g><defs><rect id="SVGID_1_" width="270.7" height="166.49"/></defs><clipPath id="SVGID_2_"><use xlink:href="#SVGID_1_"  style="overflow:visible;"/></clipPath><path style="clip-path:url(#SVGID_2_);fill:none;stroke:#000000;stroke-width:3.401;stroke-miterlimit:10;" d="M1.2,83.67 L83.67,1.2 M1.2,82.82l82.46,82.47 M270.7,82.82H2.05"/></g>
</svg>
</div>

So when I hover the mouse-pointer over an image, I'd like the svg arrow to appear and follow the mouse-pointer (or just replace the mouse-pointer) until I leave the image.因此,当我将鼠标指针悬停在图像上时,我希望 svg 箭头出现并跟随鼠标指针(或仅替换鼠标指针)直到我离开图像。

you can add cursor on hover like the code below on each of the images and I am pretty sure that the recommended format for image you want to put is png because I had a same problem for my website and I couldn't add an SVG as the cursor您可以像下面的代码一样在每个图像上添加光标,我很确定您要放置的图像的推荐格式是 png,因为我的网站有同样的问题,我无法添加 SVG 作为光标

 .image1 .image2 .image3:hover{ cursor: url('image path to your cursor'), auto ; }
 <div class="main"> <div class="image1"></div> <div class="image2"></div> <div class="image3"></div> </div>

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

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