簡體   English   中英

jQuery Smooth Scroll在網頁中不起作用

[英]jQuery Smooth Scroll not working in webpage

我正在嘗試在我的網頁中使用jQuery內部平滑。 我已經多次使用相同的代碼,沒有任何問題,但是這次它不起作用。 這是代碼的相關部分-

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

請提出一個有效的解決方案。

https://stackoverflow.com/a/10450503/6259383

有一個名為jQuery ScrollTo的插件可以幫助您http://demos.flesler.com/jquery/scrollTo/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM