// Wrap everything in this self-executing function so that other people
// don't accidentally use your variables (note the starting semi-colon,
// and the brackets at the bottom too)
;(function() {
var emotionPopover
var emotionPopoverIsVisible = false
// You don't want to set the onmousemove function every time the user
// hovers over the p tag. Just set it at the beginning.
window.onmousemove = function (e) {
// We use this "isVisible" flag so that we're not moving the box around needlessly
// when the box isn't even visible
if (emotionPopoverIsVisible) {
var x = e.clientX;
var y = e.clientY; // Every variable should have var before it
// Brackets should go around the maths bit to make sure you're doing the
// subtraction before converting the result to a string
emotionPopover.css({ top: (y - 45) + 'px' });
emotionPopover.css({ left: (x - 15) + 'px' });
}
}
// You don't need function(e) because you're not using e
$('body').on('mouseover', '.emotion-wrapper-single', function() {
// Just find the popover element once. || means "or" – i.e., set emotionPopover
// to be itself, or if it hasn't already been set, find it for the first time.
// This saves us from finding the element again every time the user hovers.
emotionPopover = emotionPopover || $(this).find('.popover')
emotionPopover.show();
emotionPopoverIsVisible = true
});
$('body').on('mouseout', '.emotion-wrapper-single', function() {
emotionPopover.hide();
emotionPopoverIsVisible = false
});
})();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.