您好,登錄后才能下訂單哦!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jq.js"></script>
<script type="text/javascript">
function goTotop(obj){
var _targetTop = $('#'+obj).offset().top;//獲取位置
jQuery("html,body").animate({scrollTop:_targetTop},300);//跳轉
}
</script>
<title>實現頁內跳轉定位到某個ID</title>
<style type="text/css">
#content {margin:0 auto;width:1000px;}
#content .box01_con {height:38px;margin:15px 0;}
#content .box01_con .menu {float:left;margin-top:8px;overflow:hidden;}
#content .box01_con .menu li {float:left;margin-right:28px;list-style-type:none;}
#content .box01_con .menu li a {color:#282828;display:block;font-size:14px;height:16px;line-height:16px;padding-left:26px;}
.box04_con {margin-top:0px;height:300px;border-top:5px solid #ccc;font-weight:bold;}
</style>
</head>
<body>
<div id="content">
<div class="box01_con">
<ul class="menu">
<li><a href="javascript:void(0)" onclick="goTotop('xwbg')">跳轉測試一</a></li>
<li><a href="javascript:void(0)" onclick="goTotop('xcshow')"><b>測試二</a></li>
<li><a href="javascript:void(0)" onclick="goTotop('wdy')">跳轉測試三</a></li>
<li><a href="javascript:void(0)" onclick="goTotop('mv')"><跳轉測試四</a></li>
<li><a href="javascript:void(0)" onclick="goTotop('dsy')">跳轉測試五</a></li>
</ul>
</div>
<div class="box04_con" id="xwbg"><h4>跳轉測試一</h4></div>
<div class="box04_con" id="xcshow" ><h4>跳轉測試二</h4></div>
<div class="box04_con" id="wdy"><h4>跳轉測試三</h4></div>
<div class="box04_con" id="mv"><h4>跳轉測試四</h4></div>
<div class="box04_con" id="dsy"><h4>跳轉測試五</h4></div>
</div>
<div >ddd</div>
<a href="javascript:void(0)" onclick="goTotop('xcshow')">跳轉測試一</a>
<!--
相關資料
http://www.dbpoo.com/js-anchor-name-id/
http://blog.csdn.net/huaishuming/article/details/8951504
-->
</body>
</html>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。