2017-02-15 3 views
0

私は1つのページのWebサイトを2つの部分に分けて、水平方向のモバイルビューにしています。したがって、ページの上部または下部にスクロール/スワイプ効果を作成しようとしています。私は検出JavaScriptを使用してページの上または下にスムーススクロール、モバイルでjquery

var bottomofDoc = $(".main_container").height(); 
$(window).scroll(function(){ 
     var cur_top = $(window).scrollTop(); 
     if(top < cur_top){ 
      direction = 'down'; 
      $('html,body').animate({scrollTop: $(document).height()}, 600); 
      console.log(direction); 
     }else{ 
      direction = 'up'; 
      $("html, body").animate({ scrollTop: 0 }, 600); 
      console.log(direction); 
     } 
     top = cur_top; 
    }); 

のこのコードを試みたが、それがちらつきと、バギーを動作し、私はそれ一度スクロールしたときにアクションを何度もやって続けています。あなたはおそらくにフラグおよび/またはタイマーを紹介したい どれでもトップにスムーズスクロールをachiveする方法のアイデアや下

+0

1. http://ejohn.org/blog/learning-from-twitter/ 2 1つはまだ実行中に、より多くのアニメーションコールを作成しないでください。 – CBroe

+0

私は試しましたが、それは役に立たなかった@CBroe –

+0

あなたが私たちに与えているすべてのものなら、私たちはあなたを助けません。 _あなたに試したことと結果を表示してください。 – CBroe

答えて

0
$(function(){ 
    $('a[href*="#"]:not([href="#"])').click(function(){ 
      if(location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname){ 
       var target = $(this.hash); 
       target = target.length ? target:$('[name=' + this.hash.slice(1) + ']'); 
       if(target.length){ 
        $('html, body').animate({ 
         scrollTop: target.offset().top 
        }, 1000); 
        return false; 
       } 
      } 
    }); 
}); 
+0

私はクリックしていない@ Brachu19 –

関連する問題