Reputation:
$(".a").animate(
{"left":"100%"},
{duration:10000, complete:function(){
//Something is triggered!! e.g
alert("a");
//Please note: In actual case it is never as simple as alert("a").
}}
);
$(".b").mouseover(function(){
$(".a").stop().animate({"top":"100px"},{duration:5000});
});
According to these, .a
would stop as long as .b
is
mouseover
-ed and animate({"top":"100px"},{duration:5000})
would
be triggered.
But I want it to alert("a")
once when .b
is mouseover
-ed
and then trigger animate({"top":"100px"},{duration:5000})
.
$(".b").mouseover(function(){
//something happens! e.g
alert("a");
$(".a").stop().animate({"top":"100px"},{duration:5000});
});
alert("a")
twice if .b
is mouseover
-ed after .a
done
animate
.stop()
's jumpToEnd parameter
and it is not idealWhenever .b
is mouseover
-ed , .a
's animte
would complete instantly and .a
would be shifted to left:100%
. I want it to stop
at where it is and yet alert("a")
before second animate
being triggered
I would be extremely grateful if someone can provide a fast and easy solution for this!
Upvotes: 0
Views: 616
Reputation: 6032
$(".a").animate(
{"left":"100%"},
{duration:10000, complete:myAfterWork} // Use the function name only
);
$(".b").mouseover(function(){
myAfterWork();
$(".a").stop().animate({"top":"100px"},{duration:5000});
});
function myAfterWork()
{
if($(".a").is(":animated"))
{
//Access $(".a") here and do your job
//Note if you use $(this) in place of $(".a") it will be different
//when called from .a's animation than from .b's animation
}
}
Upvotes: 1
Reputation: 14747
You can check if the element is currently animating by filtering it against :animated
.
$('.b').mouseover(function () {
// if NOT animating, then terminate
if (!$('.a').is(':animated')) { return; }
// carry on
});
Upvotes: 1