现在的位置: 首页 > 综合 > 正文

很简单的一个单页切换

2018年06月07日 ⁄ 综合 ⁄ 共 678字 ⁄ 字号 评论关闭
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>单页切换</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<script>
$(function(){
   $("#control a").click(function(){
        var rel=$(this).attr("href");
        var pos=$(rel).offset().top;
        $("html,body").animate({scrollTop:pos}, 800);
})
})
</script>
<div id="control" style="position:fixed;top:0px;">
	<a href="#top">head</a><br/><a href="#center">middle</a><br/><a href="#bottom">bottom</a>
</div>
<div id="top" style="height:700px;background:#f00">
</div>
<div id="center" style="height:700px;background:#ff0">
</div>
<div id="bottom" style="height:700px;background:#0ff">
</div>
</body>
</html>

抱歉!评论已关闭.