css更改鼠标指针样式,几种鼠标点击效果

2022-09-24 09:23:11 浏览数 (1)

更改鼠标指针样式

1. 鼠标指针的不同样式

平常,我们在浏览界面时,会发现鼠标的样式有所不同,鼠标的样式变化和cursor属性有关。cursor属性的几个关键字:default、pointer、wait、help、text、crosshair。

default:默认光标;

pointer:超链接的指针;

wait:表示程序正在忙;

help:指示可用帮助;

text:指示文本;

crosshair:鼠标呈现十字状;

代码语言:javascript复制
<code class="language-clike line-numbers"><span style="cursor: default;">默认光标</span>
<span style="cursor: pointer;">超链接的指针小手</span>
<span style="cursor: wait;">指程序正在忙沙漏</span>
<span style="cursor: help;">指示可用的帮助</span>
<span style="cursor: text;">指示文本</span>
<span style="cursor: crosshair;">十字状</span>

效果如下

2. 更改指针图标

更改样式图标很简单,只需要在鼠标的指针样式前面添加一个url链接一张鼠标的图片。

这些就是一些鼠标样式图,这些资源文末会给出下载。其他 具体可以自行百度下载。 代码案例

代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /** 普通指针样式**/
        body {
            width: 100vw;
            height: 100vh;
            cursor: url(./鼠标样式包/arr46.png), auto;
        }

        /** 链接指针样式**/
        a:hover {
            cursor: url(./鼠标样式包/arr43.png), pointer;
        }
    </style>
</head>

<body>
<a href="#" rel="nofollow noopener" >请点击</a>
</body>
</html>

效果可以看这里:点击这里

鼠标点击效果

1. 鼠标点击烟花特效

可以引用外包脚本文件

案例代码如下

代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /** 普通指针样式**/
        body {
            width: 100vw;
            height: 100vh;
            cursor: url('../../鼠标样式包/arr46.png'), auto;
        }

        /** 链接指针样式**/
        a:hover {
            cursor: url('../../鼠标样式包/arr1.png'), pointer;
        }
    </style>
</head>

<body>
    <!--给WordPress网站添加鼠标点击爆炸五颜六色特效-->
    <canvas class="fireworks" style="position:fixed;left:0;top:0;z-index:99999999;pointer-events:none;"></canvas>
    <script type="text/javascript" src="djtx.js"></script>
</body>

</html>

效果如下

脚本文件文会给出下载

2. 鼠标点击爱心特效

代码如下

代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 网页鼠标点击特效(爱心) -->
    <script type="text/javascript">
         ! function (e, t, a) {
            function r() {
                for (var e = 0; e < s.length; e  ) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[
                        e].y--, s[e].scale  = .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:"   s[e].x  
                    "px;top:"   s[e].y   "px;opacity:"   s[e].alpha   ";transform:scale("   s[e].scale   ","   s[e]
                    .scale   ") rotate(45deg);background:"   s[e].color   ";z-index:99999");
                requestAnimationFrame(r)
            }

            function n() {
                var t = "function" == typeof e.onclick && e.onclick;
                e.onclick = function (e) {
                    t && t(), o(e)
                }
            }

            function o(e) {
                var a = t.createElement("div");
                a.className = "heart", s.push({
                    el: a,
                    x: e.clientX - 5,
                    y: e.clientY - 5,
                    scale: 1,
                    alpha: 1,
                    color: c()
                }), t.body.appendChild(a)
            }

            function i(e) {
                var a = t.createElement("style");
                a.type = "text/css";
                try {
                    a.appendChild(t.createTextNode(e))
                } catch (t) {
                    a.styleSheet.cssText = e
                }
                t.getElementsByTagName("head")[0].appendChild(a)
            }

            function c() {
                return "rgb("   ~~(255 * Math.random())   ","   ~~(255 * Math.random())   ","   ~~(255 * Math
                    .random())   ")"
            }
            var s = [];
            e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e
                .mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) { setTimeout(e, 1e3 / 60)
                }, i(
                    ".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"
                ), n(), r()
        }(window, document);
    </script>
</body>
</html>

效果如下

3. 鼠标点击价值观文字特效

代码如下

代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <script>
        (function () {
            var a_idx = 0;
            window.onclick = function (event) {
                var a = new Array("❤富强❤", "❤民主❤", "❤文明❤", "❤和谐❤", "❤自由❤", "❤平等❤", "❤公正❤", "❤法治❤", "❤爱国❤",
                    "❤敬业❤", "❤诚信❤", "❤友善❤");

                var heart = document.createElement("b"); //创建b元素
                heart.onselectstart = new Function('event.returnValue=false'); //防止拖动

                document.body.appendChild(heart).innerHTML = a[a_idx]; //将b元素添加到页面上
                a_idx = (a_idx   1) % a.length;
                heart.style.cssText = "position: fixed;left:-100%;"; //给p元素设置样式

                var f = 16, // 字体大小
                    x = event.clientX - f / 2, // 横坐标
                    y = event.clientY - f, // 纵坐标
                    c = randomColor(), // 随机颜色
                    a = 1, // 透明度
                    s = 1.2; // 放大缩小

                var timer = setInterval(function () { //添加定时器
                    if (a <= 0) {
                        document.body.removeChild(heart);
                        clearInterval(timer);
                    } else {
                        heart.style.cssText = "font-size:16px;cursor: default;position: fixed;color:"  
                            c   ";left:"   x   "px;top:"   y   "px;opacity:"   a   ";transform:scale("  
                            s   ");";

                        y--;
                        a -= 0.016;
                        s  = 0.002;
                    }
                }, 15)

            }
            // 随机颜色
            function randomColor() {

                return "rgb("   (~~(Math.random() * 255))   ","   (~~(Math.random() * 255))   ","   (~~(Math
                .random() * 255))   ")";
            }
        }());
    </script>
</body>
</html>

效果如下

4. 其他点击特效

代码如下

代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!--光标特效仙女棒-->
    <script src="https://blog-static.cnblogs.com/files/axqa/fairyDustCursor.js"></script>
    <!--光标之泡泡-->
    <script src="https://blog-static.cnblogs.com/files/axqa/bubbleCursor.js"></script>
    <!--笑脸-->
    <script src="https://blog-static.cnblogs.com/files/axqa/emojiCursor.js"></script>
    <!--雪花-->
    <script src="https://blog-static.cnblogs.com/files/axqa/snowflakeCursor.js"></script>
    <!-- 点击后出现烟花效果 -->
    <script src="https://blog-static.cnblogs.com/files/axqa/cursor-effects.js"></script>

</body>
</html>

引用了别人的线上脚本文件,可以借鉴使用

部分资源链接

点击下载 链接:https://pan.baidu.com/s/1k03aNiNEyjo--VZ5IAcM6g 提取码:gq8v

0 人点赞