[英]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.