I am working on animating a div to move smoothly from the top to the bottom of another div. Currently, I am experimenting with mouseenter and mouseleave events along with JavaScript animations that use easing. The initial position of the animated div is at the top. My goal is for it to move down when hovered over and stay in that position until the cursor moves away. Then, when hovered over again, I want it to return to its original position at the top.
At first, I tried using mouseenter and mouseleave, but realized that it doesn't maintain the desired state upon leaving the hover area. So, I am seeking advice on which function would be more suitable for achieving this effect. I am still learning the technical terms and struggling to articulate my question clearly.
Here is the code snippet I have been working on:
function init() {
mouseenter: function(){
$(".ltrP").stop(true, true).animate({
marginTop:"170px"
},
{
duration: 1000,
easing: "easeOutBounce"
});
},
mouseleave: function(){
$(".ltrP").stop(true, true).animate({
marginTop: "0px"
},
{
duration: 1000,
easing: "easeInBounce"
});
}
});
}
window.onload = init;