【发布时间】:2012-12-07 10:29:52
【问题描述】:
我知道那里有一些类似的问题,但我正在尝试他们的解决方案,但它对我不起作用。
点击#hitbox后,如何停止下面的回调动画?在动画中,当#hitbox 悬停在上面时,div 会向外移动,当鼠标离开#hitbox 时,div 会回到原来的位置。我希望 div 在单击 #hitbox 后保持在其向外的位置,而不是移回。
var timeOut;
$('#hitbox').hover(
function() {
clearTimeout(timeOut);
// **some animation functions moving divs outward** e.g.:
$('#div').stop().animate(
{
'margin-left': '-500px',
}, 1000, 'easeOutQuart'
);
} // End first function
,
function() {
timeOut=setTimeout(function(){
// **some animation functions moving divs back in** e.g.:
$('#div').animate(
{
'margin-left':'0px',
}, 900, 'easeOutExpo' );
}, 600); //end setTimeout
} //end second callback function
); //end hover
$('#hitbox').click(function() {
$('#hitbox').css(
{'display': 'none',
});
clearTimeout(timeOut); // *****NOT WORKING*****
}); // end click
单击#hitbox 后,div 将向上移动,但当我希望它们完全保持在向外的位置时,它们会收缩(向内移动)。
clearTimeout(timeOut);
没有按照其他一些问题的建议工作。我有一种感觉,我需要的还不止这些?正如您在代码中看到的,我还尝试将#hitbox 的显示立即设置为none。
感谢您的帮助!
【问题讨论】:
标签: jquery jquery-ui animation callback hover