2016-09-13 7 views
0

私のWebページで内部スムージングを使用しようとしています。私はこの同じコードを問題なく何回も使用していますが、今回は動作しません。jQueryスムーズスクロールがWebページで機能しない

HTML - -

<html> 
<head> 
<title>Geokeep</title> 
<link rel="stylesheet" type="text/css" href="style.css"> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<script type="text/javascript" src="script.js"></script> 
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Montserrat"> 
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto"> 
</head> 
<body> 
<section id="section1"> 
        <h2 id="h2">A Million Small Things. One Bag</h2> 
        <h3 id="h3">Presenting Geokeep. The world's first recycled and solar-powered bag.</h3> 
        <a href="#section2" class="button" id="bt1">Know More</a> 
       </section> 
       <section id="section2"> 
        <span id="head"> 
         Meet Geokeep 
        </span> 
        <span id="desc"> 
         The Geokeep is packed with features that help you do your bit towards the protection of the environment. 
        </span> 
         <!--<img src="Images/DOS.png">--> 
       </section> 

とJSコード -

$(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 
     }, 900); 
     return false; 
     } 
    } 
    }); 
}); 

効率的なソリューションを提案してくださいここでは、コードの関連部分があります。

+0

あなたのコンソール上の任意のエラーを持っていますか助けることができますか? –

+0

そうではありませんが、別のWebページで同じコードを使用しています。その上で、完璧に動作しています。 –

+0

スムーススクロールを使用するhref要素と同じクラスを定義し、そのクラスをクリックしてください! –

答えて

関連する問題