【发布时间】:2014-01-14 15:43:46
【问题描述】:
我正在尝试为我的滚动设置动画,但我使用的代码似乎只是跳转到链接而不是动画。我似乎找不到为什么它不能正常工作的问题。
我在 HTML 中使用过 Jquery - 这可能是个问题吗?内外都试过了。
<doctype html>
<head>
<title>Creative Designer</title>
<link rel="stylesheet" href="css/style.css" type="text/css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(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
}, 2000);
return false;
}
}
});
});
</script>
</head>
<body>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#work">Work</a></li>
</ul>
</nav>
<section>
<h1>featured Projects</h1>
<p id="description">
I am an Creative Designer Based in Newcastle Upon Tyne
</p>
</section>
<section>
<section id="about">
This is about
</section>
<div id="mainfooter">
</div>
</body>
</html>
【问题讨论】:
标签: jquery hyperlink scroll jquery-animate