D
D
drtvader2018-03-03 09:31:52
JavaScript
drtvader, 2018-03-03 09:31:52

How to make path follow the cursor?

Hey!
How can you calculate the path element's cursor tracking?
I found this example, but it doesn't work to remake it under translate transform

$(function(){
        var mouseX = 0, mouseY = 0, limitX = 150-10, limitY = 150-10; 
        $(window).mousemove(function(e){
            var offset = $('.js-this-scroll').offset();
            mouseX = Math.min(e.pageX - offset.left, limitX);
            mouseY = Math.min(e.pageY - offset.top, limitY);
            if (mouseX < 0) mouseX = 0;
            if (mouseY < 0) mouseY = 0;
    });
        var follower = $(".js-eye");
        var xp = 0, yp = 0; 
        var loop = setInterval(function(){
                xp += (mouseX - xp) / 20;
            yp += (mouseY - yp) / 20;
            follower.css({left:xp, top:yp});
        }, 10);
    });

Redoing with left and top does not work, or maybe there are some other options?

For some reason this option doesn't work.
follower.css('transform', 'translate(' + xp + ', ' + yp + ')');/

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question