div cursor demo

div follow cursor demo

Från och med 2022-12-15. Se den senaste versionen.

// ==UserScript==
// @name         div cursor demo
// @description  div follow cursor demo
// @namespace    div_cursor
// @author       Covenant
// @version      1.0.1
// @license      MIT
// @homepage
// @match        *://*/*
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAMAAABiM0N1AAAAOVBMVEVHcEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADMzMwAAACmpqY6Ojq6urp9fX1QUFCUlJQbGxs9xjm/AAAACnRSTlMACqKHwVaUN/PaZCFdUwAAAXxJREFUWMPt2NuOgyAQBmBRhBHk+P4PuwJtNgrCYHeTXvBfNenkywBeDEzTyONwRkFeApTxPoWsm7zJtvZ0c8tECt3VCrIaQDa1pnLrtAjZY+JP7Wz6DyXx2I9NyhkKVqQAs7q4P0aIMiSEifuEOK+Lk0FJWlENWVGDhMW0FBvSdUiHmtYusWtDBSi2xBoQPWpcC3JHEW1AcF2Z2I1S5gyFtUEDCssXZ0gdOUMiVA3oq6H8+B9C+Qc5oK+HdHD0H0BBujgPoUIGNKABDej/oXw+KgQzH4VZdG9BO2IapZfhuBiDGP2WbBgtJAyjC2I89i3IIyZ2AtlYmyUMtUBaE/t8VKk6pI6SuX05kq2WHGbwf52bb+0QbTupJVs/Mom6jTJZ+5biJYthnIlsFSld+wgKel9Gb9cF6Gt2knx2ds73OW9JqhPllOx1fp8QvDVhONK7sb73+eC146z8eMDI1BtOc4by6Un4fHrbgPkZk14BFrodGmx0Wck08ll+AGC5Y59UZba/AAAAAElFTkSuQmCC
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @connect
// @run-at       document-body
// @noframes
// ==/UserScript==
function create_style(textContent,class_name){
    var style=document.createElement("style");
    style.className=class_name;
    style.textContent=textContent;
    document.body.appendChild(style);
    return style;
}

function main_02(){
    var anchor=document.querySelectorAll('a');
    var div_cursor = document.querySelectorAll('.hover-target');
    for(let i = 0; i < anchor.length; i++){
        for(let j = 0; j < div_cursor.length; j++){
            anchor[i].addEventListener('mouseenter', () => {div_cursor[j].classList.add('hover');});
            anchor[i].addEventListener('mouseleave', () => {div_cursor[j].classList.remove('hover');});
        }
    }
}
(function() {
    'use strict';
    var div_1=document.createElement('div');
    div_1.id="cursor1";
    div_1.classList.add('cursor1');
    document.body.appendChild(div_1);

    var div_2=document.createElement('div');
    div_2.id="cursor2";
    div_2.classList.add('cursor2');
    div_2.classList.add('hover-target');
    document.body.appendChild(div_2);

    var div_3=document.createElement('div');
    div_3.id="cursor3";
    div_3.classList.add('cursor3');
    div_3.classList.add('hover-target');
    document.body.appendChild(div_3);
    //div cursor css
    /*jshint multistr: true */
    create_style('.cursor1, .cursor2, .cursor3{position:fixed;border-radius:50%;transform:translateX(-50%) translateY(-50%);pointer-events:none;left:-100px;top:50%;mix-blend-mode:difference;transition:all 300ms linear;z-index:9999999;cursor:pointer;color: #212529}\n\
        .cursor1{background-color:#ffffff;height:0;width:0;z-index:9999999;border:8px solid;}\n\
        .cursor2, .cursor3{height:36px;width:36px;z-index:99998;transition:all .3s ease-out;}\n\
        .cursor2.hover, .cursor3.hover{transform:scale(2) translateX(-25%) translateY(-25%);border:none;}\n\
        .cursor2{border:2px solid #ffffff;box-shadow:0 0 12px rgba(255,255,255,.2);}\n\
        .cursor2.hover{background:white;box-shadow:0 0 0 rgba(255,255,255,.2);}','div_cursor_css');
    console.log("div mouse");
    //move
    window.onload = function(){
        console.log("window.onload");
        var div_c1 = document.getElementById("cursor1");var div_c2 = document.getElementById("cursor2");var div_c3 = document.getElementById("cursor3");
        var x, y;
        // On mousemove use event.clientX and event.clientY to set the location of the div to the location of the cursor:
        window.addEventListener('mousemove', function(event){
            x = event.clientX;
            y = event.clientY;
                if ( typeof x !== 'undefined' ){
                    div_c1.style.left=x+"px";div_c2.style.left=x+"px";div_c3.style.left=x+"px";
                    div_c1.style.top=y+"px";div_c2.style.top=y+"px";div_c3.style.top=y+"px";
                }
        }, false);
    }
    //anchor
    document.addEventListener('DOMContentLoaded', function() {console.log("DOMContentLoaded");main_02();});
    window.setTimeout(( () => main_02() ), 1000);//bak
})();