2

固定位置メニューにYSを使用していますが、Firefoxでは正常に機能していますが、IEでは機能していません。

$(function(){                     // this is the shorthand for document.ready
  $(document).scroll(function(){    // this is the scroll event for the document

      scrolltop = $(document).scrollTop();  // by this we get the value of the scrolltop ie how much scroll has been don by user
      if(parseInt(scrolltop) >= 80)         // check if the scroll value is equal to the top of navigation
      { 
          $("#navbar").css({"position":"fixed","top":"0"});       // is yes then make the position fixed to top 0
      }
      else
      {
          $("#navbar").css({"position":"absolute","top":"80px"}); // if no then make the position to absolute and set it to 80
      }
  }
}

つまり、この問題を修正する解決策はありますか?

4

3 に答える 3

1

.scroll問題は、IEがイベントをトリガーしないことだと思います。少なくとも、jsfiddleではありません。イベントを明示的にトリガーすると、問題が解決するようです。このフィドルはIE8でテストされ、機能します。コード:

$(function()
{
    $(document).scroll(function()
    {//add var here, avoid evil globals:
        var scrolltop = $(document).scrollTop();  
        if(parseInt(scrolltop) >= 80)         
        { 
            $("#navbar").css({"position":"fixed","top":"0"});       
        }
        else
        {
            $("#navbar").css({"position":"absolute","top":"80px"});
        }
    });//close properly
    $(document).scroll();//explicit call
});//close this, too
于 2012-10-09T13:40:34.573 に答える
1

jsfiddle を動作させるコードに ')' がありません(IE7 および IE9 でテスト済み)

$(function(){                     // this is the shorthand for document.ready
  $(window).scroll(function(){    // this is the scroll event for the document

      scrolltop = $(window).scrollTop();  // by this we get the value of the scrolltop ie how much scroll has been don by user
      if(parseInt(scrolltop) >= 80)         // check if the scroll value is equal to the top of navigation
      { 
          $("#navbar").css({"position":"fixed","top":"0"});       // is yes then make the position fixed to top 0
      }
      else
      {
          $("#navbar").css({"position":"absolute","top":"80px"}); // if no then make the position to absolute and set it to 80
      }
  }); //here
});//here
于 2012-10-09T13:14:37.537 に答える