jQuery - Follow the cursor with a DIV

Peter picture Peter · Aug 2, 2010 · Viewed 113.3k times · Source

How can I use jQuery to follow the cursor with a DIV?

Answer

jAndy picture jAndy · Aug 2, 2010

You can't follow the cursor with a DIV, but you can draw a DIV when moving the cursor!

$(document).on('mousemove', function(e){
    $('#your_div_id').css({
       left:  e.pageX,
       top:   e.pageY
    });
});

That div must be off the float, so position: absolute should be set.