Skip to content

Instantly share code, notes, and snippets.

@scottsappen
Created July 1, 2013 14:59
Show Gist options
  • Save scottsappen/5901590 to your computer and use it in GitHub Desktop.
Save scottsappen/5901590 to your computer and use it in GitHub Desktop.
Your mouse is a magician - add on to https://gist.github.com/scottsappen/5901573
I decided to make the text follow the mouse.
First, download JqueryUI and place it in your usual js location. This library gives you all kinds of nice stuff, like moving a <div> around a page that follows your mouse.
<script src="/js/vendor/jquery-ui.min.js"></script>
Here’s my <div> by the way, this is what I’ll be using.
<div id="forworldmapcomment" style="position:absolute;"></div>
In your $(document).ready(function() {}); function add this:
$("#forworldmap").mousemove(function(e){
$("#forworldmapcomment").position({
my: "bottom-20",
of: e,
collision: "fit"
});
});
That’s all there is to it, your <div> with id forworldmapcomment will follow the mouse around the screen.
I’ve positioned it 20 pixels above the event (mouse)’s position to avoid most conflicts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment