鼠标演示

更富有弹性的光标

目前為 2024-02-24 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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";
        })
})();