このドロップダウンを正しく動作させるのに多少の困難があります。ドロップダウンされた要素にカーソルを合わせると、開いたままになります。マウスがその要素の上に置かれているかどうかを 0.5 秒ごとにチェックし、そうであれば何もせず、そうでなければドロップダウン メニューを閉じる関数を作成しました。これが私の意味を確認するための私のフィドルです:http://jsfiddle.net/KyCyB/
ここに私のJSがあります:
$('.navBarClickOrHover').mouseover(function () {
var targetDrop = $(this).attr('targetDropDown');
if ($('.dropdownCont[isOpen="true"]').length != 0) {
$('.dropdownCont[isOpen="true"]').attr('isOpen', 'false');
$('.dropdownCont[isOpen="true"]').animate({
"height": "0px"
}, 200, function () {
$('#' + targetDrop).attr('isOpen', 'false');
$('#' + targetDrop).animate({
"height": "200px"
});
});
} else {
$('#' + targetDrop).animate({
"height": "200px"
});
}
}).mouseout(function () {
var targetDrop = $(this).attr('targetDropDown');
setTimeout(function () {
if ($('#' + targetDrop).attr('isHoveredOver') == 'true') {
//DONOTHING
} else {
$('#' + targetDrop).animate({
"height": "0px"
});
}
}, 500);
});
$('.dropdownCont[isOpen="true"]').mouseover(function () {
$(this).attr('isHoveredOver', 'true');
}).mouseout(function () {
$(this).attr('isHoveredOver', 'false');
});
長くて反復的なコードで申し訳ありません。正しく動作するようになったら、もう少しオブジェクト指向にするつもりでした。いじり続けて、思い通りに動作させようとしました。間違いなく立ち往生。以前にリンクを見逃したことがある場合は、ここにもう一度あります: http://jsfiddle.net/KyCyB/ これに対するヘルプまたは別のアプローチは素晴らしいでしょう! ありがとう!