鼠标演示

更富有弹性的光标

当前为 2024-02-24 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         鼠标演示
// @namespace    https://www.cnblogs.com/thetheOrange
// @version      2024-01-25
// @description  更富有弹性的光标
// @author       thetheOrange
// @match        *://*/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    // 创建一个鼠标演示指针
    const body = document.querySelector("body");
    const cursor = document.createElement("div");
    // 添加样式
    cursor.setAttribute("style",`
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background-color: blue;
    position: absolute;
    top: 0;
    left: 0;
    transform: translate(-50%, -50%);
    transition: 250ms cubic-bezier(0.555, 1.600, 0.370, 0.915) all;
    opacity: 0.2;
    pointer-events: none;
    z-index:10000`);
    // 插入元素
    body.appendChild(cursor);
    // 绑定鼠标移动事件
    document.addEventListener("mousemove", (event)=>{
        cursor.style.top = `${event.pageY}px`;
        cursor.style.left = `${event.pageX}px`;
    });
    // 绑定鼠标长按事件
    let ori_width = parseInt(getComputedStyle(cursor).width);
    let ori_height = parseInt(getComputedStyle(cursor).height);
    document.addEventListener("mousedown", () => {
        cursor.style.width = (parseInt(getComputedStyle(cursor).width) + 100) + "px";
        cursor.style.height = (parseInt(getComputedStyle(cursor).height) + 100) + "px";
        })
    document.addEventListener("mouseup", () => {
        // 恢复到原来的宽高
        cursor.style.width = ori_width + "px";
        cursor.style.height = ori_height + "px";
        })
})();