下面是HTML & jQuery代码我有:JQuery的动画延迟问题
HTML我有:
<div class="announcement">
<img id="imgBanner" style="cursor: pointer;" onmouseover="showPopup();" />
</div>
<div id="divArrow" class="arrow">
<img id="imgExpandContract" style="cursor: pointer;" alt="Arrow" border="0"onmouseover="showPopup();" />
</div>
<div id="window">
<!-- some html content acting as a fly-out -->
</div>
JS代码:
var imgBanner = "xyx.png";
var imgArrowExpand = "xyx.png";
var imgArrowContract = "xyx.png";
var isDone = false;
function showPopup() {
try {
var imgWidth = $("#imgExpandContract").width();
var posX = document.getElementById("imgExpandContract").offsetLeft + imgWidth;
if (!$("#window").is(":animated")) {
$("#window").animate({ left: posX }, 800, 'easeOutSine',
function() {
isDone = true;
$("#imgExpandContract").attr("src", imgArrowContract);
$("#window").bind("mouseenter", function() { $("#window").bind("mouseleave", function() { closePopup(); }); });
}
);
}
}
catch (error) {
//disable the banner, arrow images
document.getElementById("imgBanner").style.visibility = 'hidden';
document.getElementById("imgExpandContract").style.visibility = 'hidden';
}
}
function closePopup() {
try {
if (isDone) {
var posY = $("#window").width();
$("#window").animate({ left: -posY }, 600, 'linear',
function() {
isDone = false;
$("#imgExpandContract").attr("src", imgArrowExpand);
$("#window").unbind("mouseenter");
$("#window").unbind("mouseleave");
}
);
}
}
catch (error) {
//disable the banner, arrow images
document.getElementById("imgBanner").style.visibility = 'hidden';
document.getElementById("imgExpandContract").style.visibility = 'hidden';
}
}
目前我有2个问题
:
当我将鼠标移出#window div时,在调用mouseleave之前有一个小的延迟。我怎样才能让它消失?它有点保持几毫秒,然后注视老鼠叶子。
mouseleave事件有时不会触发......偶尔会发生,但会发生。我必须在#window div上移动我的鼠标并移回(基本上必须执行两次)?任何人都可以让我知道为什么会发生这种情况,我能如何处理?
除了在JQuery中使用animate()之外,还有更好的解决方案吗?对所有/任何建议感到高兴。我正在尝试使用div内的内容执行飞出/幻灯片效果。
非常感谢您的帮助
对于$(element).stop(true)为+1;我解决了我的问题,虽然我的问题不同:) – Dimskiy 2010-08-05 17:28:36