// CSS
#popupUser{width:180px; height:180px; position:absolute; background:#FFFFFF; border:#000000 2px solid; display:none;}
.viewUser{width:173px; float:left; padding:10px; margin-left:20px; margin-bottom:20px; border:#000000 1px solid;}
// HTML + Jquery
<body>
<div class="contenitore">
<script type="text/javascript">
$(document).ready(function() {
$(".viewUser")
.mousemove(function (e) {
if($("#popupUser").css('display')=='none') {
$("#popupUser").css({left:e.pageX+15, top:e.pageY -190}).show();
alert("None");
}
})
.mouseout(function () {
$("#popupUser").hide();
});
});
</script>
<div class="viewUser">
Content
</div>
</div>
<div id="popupUser"> </div>
</body>
What i’d like to aspect is that, when i go on the div viewUser with the mouse, the alert is showed (printing none). After this, until I’ll left that div, I must never seen another alert (because the display property, when I call the .show() function, should be setted as block).
But that’s not happens : in fact some time (when I still moving on the viewUser with the mouse) I see the alert. Why this behaviour?
Cheers
UPDATE
In fact what i’d like to do is this : when i go on the mouse in the viewUser div, i’ll do an ajax call to the server to get some info and append it to popupUser. So, i won’t to call this ajax call everytime i move the mouse on the div 🙂
Because when the popup appears and the mouse is on it, the mouseout of the
.viewUserfires and closes it again..If you want to track the element then reposition it in relation to the mouse.
demo: http://www.jsfiddle.net/gaby/RQhTp/
The solution (after comments) is to use a timeout for the mouseout so that the div has enough time to re-position itself..
demo: http://www.jsfiddle.net/gaby/RQhTp/3/