0

IE 8/9 を除くすべての場所で正常に動作するロケーション スイッチ メニューを取得しました (古いものはターゲットにしません)。私は基本的にここで選択スタイルのオブジェクトが必要ですが、選択要素のカスタム スタイルのすべての頭痛の種を経験したくありません。prepend() を使用して、クリックされた li 要素を順不同リストの先頭に移動しています。問題は、IE 8 および 9 では、移動された li がまだホバリングされていると認識しているように見えるため、リストからマウスを離しても :hover スタイルがクリアされないことです。これらのブラウザーで :hover CSS をクリアするには、一番上の li 要素の上にマウスを戻す必要があります。(maxWidth 部分は動的なコンテンツのサイズ変更に関連しており、問題にはならないようです。)

HTML:

<div id="locationselector">
<ul>
<li class="current">Home</li>
<li>Banf</li>
<li>Pago Pago</li>
</ul>
</div>

jQuery:

<script type="text/javascript">
$(document).ready(function() {
  var maxWidth = Math.max.apply( null, $( '#locationselector li' ).map( function () {
  return $( this ).outerWidth( true );
  }).get() );
  $("#locationselector").width(maxWidth + 37);
  $('#locationselector li').click(function(e) {
    e.preventDefault();
    $('#locationselector li.current').removeClass('current');
    $(this).parent().prepend(this);
    $(this).addClass('current');
  });
});
</script>

CSS:

<style type="text/css">
#locationselector {
    background: url(http://zgraphicsdev.com/stackoverflow/location-switch-bg.png) no-repeat;
    height: 30px;
    display: inline-block;
    margin: -10px 5px;
    position: relative;
    border-radius: 6px;
    -webkit-border-radius: 6px;
    -webkit-box-shadow:  0px 0px 2px 2px rgba(0, 0, 0, .3);
    box-shadow:  0px 0px 2px 2px rgba(0, 0, 0, .3);
}
#locationselector ul {
    height: 30px;
    margin: 3px 0 0 27px;
    padding: 0;
    list-style-type: none;
    position: absolute;
    overflow: hidden;
}
#locationselector ul:hover {
    background-color: #d9d9d9;
    overflow: visible;
    height: auto;
    -webkit-box-shadow:  5px 5px 5px 0px rgba(0, 0, 0, .3);
    box-shadow:  5px 5px 5px 0px rgba(0, 0, 0, .3);
}
#locationselector ul li {
    background-color: transparent;
    color: #494949;
    font-family: "museo-sans", "Museo Sans 500", sans-serif;
    font-weight: 500;
    font-size: 13px;
    line-height: 14px;
    padding: 6px 3px;
    margin: 0;
    white-space: nowrap;
    text-align: left;
    cursor: pointer;
}
#locationselector ul li:hover {
    background-color: #FFFFFF;
}
#locationselector ul li.current {
    color: #FFFFFF;
}
#locationselector ul li.current:hover {
    color: #494949;
}
#locationselector ul:hover li.current {
    color: #494949;
}
</style>

御時間ありがとうございます!

4

1 に答える 1

1

jQuery で event.target を指定するとうまくいくかもしれません。

すなわち:

$("#main").on("mouseover",function(e){

if(e.target=="Any Specific Child"){

//Do something
}

})

これは、mouseoutmouseentermouseleaveイベントでも使用できます。

于 2013-08-21T17:55:52.700 に答える