以下は私が持っているHTMLと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 に移動して戻る必要があります (基本的に 2 回行う必要があります)。なぜこれが起こるのか、どうすれば対処できるのか誰か教えてもらえますか?
JQueryでanimate()を使用する以外に、これを行うためのより良い解決策はありますか? すべて/任意の提案を喜んでいたします。div 内のコンテンツで fly-out/slideIn 効果を実行しようとしています。
ご助力ありがとうございます