私はイメージを持っていて、その上にマウスを置くと、2つの矢印(左右の側)にフェードし、マウスアウトするとそれらの矢印が消えます。私の問題は、ユーザーが矢印上を移動すると、画像がマウスオーバー(矢印が画像の上に浮いているため)とみなし、矢印を消して、マウスを移動するまでフェードイン/アウトの無限ループを引き起こします。マウスがマウスの上を移動するときに矢が消えないようにする最良の方法は何ですか?興味がある人のためにjQueryマウスオーバーの問題
$(".arrow").mouseover(function() {
overArrow = 1;
$("#debug_oar").text(1)
})
$(".arrow").mouseout(function() {
overArrow = 0;
$("#debug_oar").text(0)
})
$("#image").mouseout(function() {
$(".arrow").fadeOut(250,function() { $(".arrow").remove();})
})
$("#image").mouseover(function() {
if(overArrow == 0) {
$("#image").after("<div class='arrow' id='lArrow' style='display:none;position:absolute;'>←</div><div class='arrow' id='rArrow' style='display:none;position:absolute;'>→</div>")
// Define variables...
aWidth = $("#lArrow").width();
aHeight = $("#lArrow").height();
height = $("#image").height()
width = $("#image").width()
pos = $("#image").position();
// Calculate positioning
nHeight = height/2
y = pos.top + nHeight - (aHeight/2)
// Position the left arrow
$("#lArrow").css("top",y)
$("#lArrow").css("left",pos.left+10)
// Now the right...
$("#rArrow").css("top",y)
$("#rArrow").css("left",pos.left+width-aWidth-20)
// Display 'em
$(".arrow").fadeIn(250);
// Debug info
$("#debug_x").text(pos.left)
$("#debug_y").text(y)
$("#debug_height").text(height)
}
})
おかげ
:ここ
は、いくつかのコードだ...私はあなたが以下を参照してくださいよ一つの方法を、試してみたが、それはワークアウトされてhasen't$("#image").mouseenter(function() {
$("#image").append("<div class='arrow' id='lArrow' style='display:none;position:absolute;'>←</div><div class='arrow' id='rArrow' style='display:none;position:absolute;'>→</div>")
// Define variables...
aWidth = $("#lArrow").width();
aHeight = $("#lArrow").height();
height = $("#image").height()
width = $("#image").width()
pos = $("#image").position();
// Calculate positioning
nHeight = height/2
y = pos.top + nHeight - (aHeight/2)
// Position the left arrow
$("#lArrow").css("top",y)
$("#lArrow").css("left",pos.left+10)
// Now the right...
$("#rArrow").css("top",y)
$("#rArrow").css("left",pos.left+width-aWidth-20)
// Display 'em
$(".arrow").fadeIn(250);
// Debug info
$("#debug_x").text(pos.left)
$("#debug_y").text(y)
$("#debug_height").text(height)
});
$("#image").mouseleave(function() {
$(".arrow").fadeOut(250,function() { $(".arrow").remove();})
})
これはうまくいきました。画像がdivで囲まれていたので、矢印がdivのコンテンツに追加されました。その後、mouseneterとmouseleaveを使用しました。ありがとう! –