2017-04-26 22 views
0

スムーズなスクロールプラグインを試して壁に頭を打つと、サインアップボタンがスムーズにスクロールして#targetセクションまでスムーズに行かないことがあります。スムーズスクロールが正しく動作しない

私はハイブの心を助けてください、私はCSSのトリックのコードを使用しています。

$('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; 
    } 
} 
}); 

あなたは(それは多分少し速い500に多分それを変更しています)あなたのコードをキャンセルして、これを試してみる

https://codepen.io/samducker/pen/RVoORy

答えて

1

ですべてのHTML、CSS、および他のJSとペンを見ることができます

/*Scroll Down Button*/ 
$(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

私はすべてのCSSのトリックの例で作品を使用していた前のコードはどのように来る私のページで動作しませんでしたか? –

+0

私は分かりません。たぶんコピーの貼り付けの問題です。あなたはあなたのソリューションにとどまり、( 'a [href * = "#]:not([href =#])) "]) ') – RacoonOnMoon

+0

私は貪欲になりたくはありませんが、グリーンティックで正しい答えを選択できますか?役に立った – RacoonOnMoon

0

あなたのjQueryのセレクタが正しくないと思わ:あなたのボタンとアンカーの間にそれほど多くのコンテンツを持っている場合、それは少しラグかもしれません。そのため、ボタンをクリックするとクリック機能が起動せず、デフォルトのアンカー動作にフォールバックします。あなたのコードをフォークし、jQueryセレクタをaに変更しました。https://codepen.io/anon/pen/VbmNXd

jQueryセレクタをアプリケーションに適したものに変更してください。

関連する問題