我目前有以下代码:
$("ol#homePortfolio li img").fadeto("slow",1.0);
$("ol#homePortfolio li img").hover(
function() {
$("ol#homePortfolio li img").fadeto("slow",0.8);
},function() {
$("ol#homePortfolio li img").fadeto("slow",1.0);
}
);
但是,当我多次将褪色和淡入淡出的图像悬停在图像上时,我该如何应用停止,这样只发生一次?
解决方法
你可能正在寻找
stop功能. (jquery.com今天有问题,这里是
Google’s cached copy的链接.)停止停止任何正在进行中的动画.
只需在开始动画之前调用它即可停止该元素上的任何先前的动画:
$("ol#homePortfolio li img").stop().fadeto("slow",0.8);
// ^----
你会想玩一点(我不会做很多可能重叠的动画),在中间停止一些动画可能意味着你需要确保将元素重置为已知状态.或者使用jumpToEnd标志:
$("ol#homePortfolio li img").stop(false,true).fadeto("slow",0.8);
// ^ ^-- true = jump to the end of the animation
// |--------- false = don't clear the queue (you may
// want true here,to clear it)