Jquery animate while hover
I'm looking for a very basic feature: I want to animate a div in it's position while the mouse hovers over a certain area of the window. I've already figured out how and when to fire off the animate function the problem is, that it's limited in its time. I'm looking for a way to move the div relative to it's position while hovering.
Cheers, janik
Edit:
I've created a JDfiddle. Didn't know about that before. jsfiddle.net/Ru2mZ/7 To render out my problem: I want a continuous movement or animation of an object while the mouse is over the button. So a basic animation like $('#id').animate({left: 100},100) wouldn't work since it's limited to a fixed end position and a fixed amount 开发者_开发知识库of time.
$('#someDiv').bind('mouseenter', function () {
this.iid = setInterval(function () {
aniDiv();
}, 25);
}).bind('mouseleave', function () {
this.iid && clearInterval(this.iid);
});
function aniDiv() {
$('#someDiv').animate({ marginLeft: '-=200px' },10);
};
Here is the documentation of the hover function. http://api.jquery.com/hover/
Basically, you have to
$("#div-id").hover(
function () {
//Do whatever you want to any element when the mouse is on the div with id: div-id. If you want to change anything related to the div being hoved, use the $(this) selector.
},
function () {
//Do whatever you want to any element when the mouse was on the div with id: div-id and leaves it. If you want to change anything related to the div being hoved, use the $(this) selector.
}
);
精彩评论