How do you make a picture follow your mouse pointer with jquery?

The answer (using James Black’s help) is:

HTML

  <div id="sketch"></div>
  <img src="https://stackoverflow.com/questions/1677848/cat.jpg" class="follow" style="position: absolute;"/>

JQuery

$("#sketch").mousemove(function(e){
      $('.follow').css({'top': e.clientY - 20, 'left': e.clientX - 20});
});

Jsbin demo here.

Leave a Comment