1

私は「スティッキースクロール」ナビゲーションを追加しています。これは、ナビゲーションがブラウザの上部に到達するまで移動できるようにする、つまり常にユーザーの目に留まるようにする、と呼ばれていると思います。私はそれをクローム、ファイアフォックス、IEで動作させることができました。

ただし、jqueryの一部では、停止する上部マージンを変更できます。

とにかく、ブラウザごとに上部マージンを異なる方法で設定できますか?たとえば、chromeは10pxにしたい、IEは5pxにしたい、firefoxは何らかの理由で画面全体をNavで取得するので、変更する必要はありません。

これがそのJqueryです

<script type="text/javascript">
    $(function(){ // document ready

      if (!!$('.sticky').offset()) { // make sure ".sticky" element exists

        var stickyTop = $('.sticky').offset().top; // returns number 

        $(window).scroll(function(){ // scroll event

          var windowTop = $(window).scrollTop(); // returns number 

          if (stickyTop < windowTop){
            $('.sticky').css({ position: 'fixed', top: 0 });
          }
          else {
            $('.sticky').css('position','static');
          }

        });

      }

    });
</script>

あなたはトップマージンセクショントップを見ることができます:0

何か案は?

ありがとう

4

1 に答える 1

2

IF you want to go this route you can use $.browser (http://api.jquery.com/jQuery.browser/) to test which browser the user is using. This works in most cases, but it could break down if the user has changes the user-agent setting of his browser.

What I suggest you do however is find out why this behavior exist and sold the underlying problem. It you cannot fix it or you have run out of time you can alway fall back to hacks like $.browser. :)

于 2012-04-08T09:33:37.207 に答える