I have created a div to slide in from outside of the viewport and place itself over the original div.
The animation is triggered by hovering over box1
. This will bring box2
in place of box1
.
When the mouse leaves the box2
div, it will be placed outside of the viewport again.
However, slow cursor movement within this div will result in animation triggering rapidly.
$(document).ready(function() {
$('.box1').mouseover(function() {
$('.box2').stop().animate({
top: 0
}, 100);
}).mouseout(function() {
$('.box2').stop().animate({
top: '-200px'
}, 100);
});
});
The following fiddle should present the problem.
.mouseout()
is.mouseenter()
, not.mouseover()
.box2
will appear under your cursor and.mouseout()
is triggered. You could bypass that problem by using.mousemove()
where you have mouse position available.