I recently decided that I want an icon to follow the mouse on my web site. So I added the following to a JavaScript file that every page on my site uses
$(document).ready(function() {
var mouseFollowerHTML = "<img class='mouse-follower' src='/images/space_needle_icon.png' alt='space needle'/>";
$('.maincontent').append(mouseFollowerHTML);
});
$(document).mousemove(function(e) {
$('.mouse-follower').offset({
left: e.pageX,
top: e.pageY + 20
});
});
with the intention that it would inject an image into the maincontent
element (which is on every page) and then have the image follow the mouse. But it's not working. I've tried adding an alert to the $(document).ready(...)
function, but nothing happened.
Please correct me in the error(s) of my ways.