0

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.

1 Answers1

1

Check that you connected jQuery to the of the page:

<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>

And check out this jsbin: http://jsbin.com/sipaxaqipo/1/edit?html,js,console,output (it works fully with your code), so your code is correct. Mistake is somewhere in another part of site, hope you just forgot to connect jQuery.

Kichrum
  • 607
  • 7
  • 8