<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/style.css" />
<script type="text/javascript" src="js/jquery-1.8.3.min.js" ></script>
<style>
*{margin: 0;padding: 0;}
.div{height: 500px;border-top: 1px solid #000000;text-align: center;font-size: 50px;line-height: 500px;}
.nav{position: fixed;top: 200px;right: 0px;}
.top{}
</style>
</head>
<body>
<div class="nav">
<a href="#div1">div1</a><br />
<a href="#div2">div2</a><br />
<a href="#div3">div3</a><br />
<a href="#div4">div4</a><br />
<a href="#div5">div5</a><br />
<a class="top" href="#">返回顶部</a>
</div>
<div class="div" id="div1">div1</div>
<div class="div" id="div2">div2</div>
<div class="div" id="div3">div3</div>
<div class="div" id="div4">div4</div>
<div class="div" id="div5">div5</div>
<script type="text/JavaScript">
$(document).ready(function() {
$('a[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) {
var targetOffset = $target.offset().top;
$('html,body').animate({
scrollTop: targetOffset
},
500);
return false;
}
}
});
$(".top").click(function() {
$("html,body").animate({scrollTop:0}, 500);
});
});
</script>
</body>
</html>
超简单jq锚点动画效果+返回顶部
最新推荐文章于 2020-11-21 16:44:59 发布