Search code examples
htmljquerymouse-cursor

jQuery - Follow the cursor with a DIV


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


Solution

  • 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.