2016-09-13 5 views
0

Ich versuche, eine interne jQuery glatt in meiner Webseite zu verwenden. Ich habe diesen Code einige Male ohne Probleme benutzt, aber dieses Mal funktioniert es nicht. Hier ist der relevante Teil des Codes -jQuery Smooth Scroll funktioniert nicht in der Webseite

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> 

Und der JS-Code -

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

Bitte legen nahe, eine effiziente Lösung.

+0

Haben Sie einen Fehler auf der Konsole? –

+0

Nicht als solche verwende ich den gleichen Code auf einer anderen Webseite und da drüben funktioniert es einwandfrei. –

+0

Definieren Sie die gleiche Klasse für die a href-Elemente, die Sie mit smooth scroll verwenden, und klicken Sie dann auf diese Klasse! –

Antwort