Skip to content

Instantly share code, notes, and snippets.

@eddiejhong
Last active December 19, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddiejhong/5986720 to your computer and use it in GitHub Desktop.
Save eddiejhong/5986720 to your computer and use it in GitHub Desktop.
This is useful in creating popup text when mousing over an element on a page. Only one line of html is required!
$('body').on({
mouseenter: function(e) { //the argument 'e' allows for the use of position tracking
$('#popup_text').css({ //using the position of the current target (element which is moused over), we can position the popup text using CSS
left: $(this).offset().left-130,
top: $(this).offset().top-5
});
},
mouseleave: function(e) { //once the mouse has left the target element, the CSS moves the popup text out of view
$('#popup_text').css({
left: -9999,
});
}
},', .top3star'); // ".top3star" was the element that we were interested in placing popup text near
//Example of html:
//<div id="popup_text">This is popup text!</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment