0

I have a code for a custom cursor, and the cursor, which is a ball/circle, was supposed to grow/scale when hovering over a link, if you see the code below, this function is there, but it is not working, does anyone know what's wrong? Thank you in advance. The code is from codepen: https://codepen.io/clementGir/pen/RQqvQx


<div class="cursor">
    <div class="cursor__ball cursor__ball--big ">
        <svg height="30" width="30">
            <circle cx="15" cy="15" r="12" stroke-width="0"></circle>
        </svg>
    </div>

    <div class="cursor__ball cursor__ball--small">
        <svg height="10" width="10">
            <circle cx="5" cy="5" r="4" stroke-width="0"></circle>
        </svg>
    </div>
</div>

<style>
    body .cursor {
        pointer-events: none;
    }

    body .cursor__ball {
        position: fixed;
        top: 0;
        left: 0;
        mix-blend-mode: difference;
        z-index: 1000;
    }

    body .cursor__ball circle {
        fill: #f7f8fa;
    }
</style>

<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.3/TweenMax.min.js"></script>

<script>
    const $bigBall = document.querySelector('.cursor__ball--big');
    const $smallBall = document.querySelector('.cursor__ball--small');
    const $hoverables = document.querySelectorAll('a');

    // Listeners
    document.body.addEventListener('mousemove', onMouseMove);
    for (let i = 0; i < $hoverables.length; i++) {
        if (window.CP.shouldStopExecution(0)) break;
        $hoverables[i].addEventListener('mouseenter', onMouseHover);
        $hoverables[i].addEventListener('mouseleave', onMouseHoverOut);
    }

    // Move the cursor
    window.CP.exitedLoop(0); function onMouseMove(e) {
        TweenMax.to($bigBall, .4, {
            x: e.clientX - 15,
            y: e.clientY - 15
        });

        TweenMax.to($smallBall, .1, {
            x: e.clientX - 5,
            y: e.clientY - 7
        });
    }

    // Hover an element
    function onMouseHover() {
        TweenMax.to($bigBall, .3, {
            scale: 4
        });
    }
    function onMouseHoverOut() {
        TweenMax.to($bigBall, .3, {
            scale: 1
        });
    }
</script>
HunterD
  • 3
  • 4
  • The codepen works OK, your code however gives a JS error. Please look at it carefully and make it into a snippet that we can run - this might help you do that and with luck will point you towards what is wrong: https://stackoverflow.com/help/minimal-reproducible-example – A Haworth Apr 02 '22 at 16:42
  • Thank you. I am not sure, I made it into a snippet. I am actually new at this JS stuff. I am not sure it is right. Please let me know if it's working now. Thank you. – HunterD Apr 02 '22 at 17:31
  • It isn’t yet a runnable snippet. Please read through the guide on how to create one. – A Haworth Apr 02 '22 at 17:43
  • I am unable to make it, it gives me JS errors everywhere. I am sorry, I have no knowledge to make it run... – HunterD Apr 02 '22 at 18:49
  • Make it into a snippet and I will take a look. – A Haworth Apr 02 '22 at 18:51
  • Yes, that's what I am trying, I read the guide, can't figure out how to make a snippet, I am new on stack overflow and js as well... – HunterD Apr 02 '22 at 18:56

0 Answers0