摘要:不用锚点也可以平滑滚动到页面的指定位置. 代码如下: <!DOCTYPE html> <html > <head> <meta content="text/html; charset=utf-8" /> <title>ScrollTo:平滑滚动到页面指定位置</title> <link rel="stylesheet" type="text/css" href="../css/main.css" /> <style type="text/css"> .nav{width:500px;margin:10px auto;} .nav li{float:left; width:100px; height:24px; line-height:24px} .box{height:500px} .box h3{height:32px; line-height:32px; padding-left:20px; font-size:14px} .clear{clear:both} html,body,p,span,h1,h2,h3,h4,h5,h6,p,pre,a,code,em,img,small,strong,sub,sup,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent} a{color:#007bc4/*#424242*/; text-decoration:none;} a:hover{text-decoration:underline} ol,ul{list-style:none} table{border-collapse:collapse;border-spacing:0} body{height:100%; font:12px/18px "Microsoft Yahei", Tahoma, Helvetica, Arial, Verdana, "/5b8b/4f53", sans-serif; color:#51555C; background:#162934 url(../images/body_bg.gif) repeat-x} img{border:none} #main{width:910px; min-height:600px; margin:30px auto 0 auto; background:#fff; -moz-border-radius:12px;-khtml-border-radius: 12px;-webkit-border-radius: 12px; border-radius:12px;} h2.top_title{margin:4px 20px; padding-top:15px; padding-left:20px; padding-bottom:10px; border-bottom:1px solid #d3d3d3; font-size:18px; color:#a84c10;} </style> <script type="text/javascript" src="https://jt.875.cn/js/jquery.js"></script> <script type="text/javascript" src="https://jt.875.cn/js/scrollto.js"></script> <script type="text/javascript"> $(function(){ $(".nav_pro").click(function(){ $.scrollTo('#pro',500); }); $(".nav_news").click(function(){ $.scrollTo('#news',800); }); $(".nav_ser").click(function(){ $.scrollTo('#ser',1000); }); $(".nav_con").click(function(){ $.scrollTo('#con',1200); }); $(".nav_job").click(function(){ $.scrollTo('#job',1500); }); }); </script> </head> <body> <p id="main"> <h2 class="top_title">ScrollTo:平滑滚动到页面指定位置</h2> <ul class="nav"> <li><a href="#" class="nav_pro">产品展示</a></li> <li><a href="#" class="nav_news">新闻中心</a></li> <li><a href="#" class="nav_ser">服务支持</a></li> <li><a href="#" class="nav_con">联系我们</a></li> <li><a href="#" class="nav_job">人才招聘</a></li> </ul> <p class="clear"></p> <p id="pro" class="box"> <h3>产品展示</h3> </p> <p id="news" class="box"> <h3>新闻中心</h3> </p> <p id="ser" class="box"> <h3>服务支持</h3> </p> <p id="con" class="box"> <h3>联系我们</h3> </p> <p id="job" class="box" style="height:680px"> <h3>人才招聘</h3> </p> </p> </body> </html>

小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

不用锚点也可以平滑滚动到页面的指定位置

. 代码如下:

<!DOCTYPE html>
<html >
<head>
<meta content="text/html; charset=utf-8" />
<title>ScrollTo:平滑滚动到页面指定位置</title>
<link rel="stylesheet" type="text/css" href="../css/main.css" />
<style type="text/css">
.nav{width:500px;margin:10px auto;}
.nav li{float:left; width:100px; height:24px; line-height:24px}
.box{height:500px}
.box h3{height:32px; line-height:32px; padding-left:20px; font-size:14px}
.clear{clear:both}
html,body,p,span,h1,h2,h3,h4,h5,h6,p,pre,a,code,em,img,small,strong,sub,sup,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}
a{color:#007bc4/*#424242*/; text-decoration:none;}
a:hover{text-decoration:underline}
ol,ul{list-style:none}
table{border-collapse:collapse;border-spacing:0}
body{height:100%; font:12px/18px "Microsoft Yahei", Tahoma, Helvetica, Arial, Verdana, "/5b8b/4f53", sans-serif; color:#51555C; background:#162934 url(../images/body_bg.gif) repeat-x}
img{border:none}
#main{width:910px; min-height:600px; margin:30px auto 0 auto; background:#fff; -moz-border-radius:12px;-khtml-border-radius: 12px;-webkit-border-radius: 12px; border-radius:12px;}
h2.top_title{margin:4px 20px; padding-top:15px; padding-left:20px; padding-bottom:10px; border-bottom:1px solid #d3d3d3; font-size:18px; color:#a84c10;}
</style>
<script type="text/javascript" src="https://jt.875.cn/js/jquery.js"></script>
<script type="text/javascript" src="https://jt.875.cn/js/scrollto.js"></script>
<script type="text/javascript">
$(function(){
$(".nav_pro").click(function(){
$.scrollTo('#pro',500);
});
$(".nav_news").click(function(){
$.scrollTo('#news',800);
});
$(".nav_ser").click(function(){
$.scrollTo('#ser',1000);
});
$(".nav_con").click(function(){
$.scrollTo('#con',1200);
});
$(".nav_job").click(function(){
$.scrollTo('#job',1500);
});
});
</script>
</head>
<body>
<p id="main">
<h2 class="top_title">ScrollTo:平滑滚动到页面指定位置</h2>
<ul class="nav">
<li><a href="#" class="nav_pro">产品展示</a></li>
<li><a href="#" class="nav_news">新闻中心</a></li>
<li><a href="#" class="nav_ser">服务支持</a></li>
<li><a href="#" class="nav_con">联系我们</a></li>
<li><a href="#" class="nav_job">人才招聘</a></li>
</ul>
<p class="clear"></p>
<p id="pro" class="box">
<h3>产品展示</h3>
</p>
<p id="news" class="box">
<h3>新闻中心</h3>
</p>
<p id="ser" class="box">
<h3>服务支持</h3>
</p>
<p id="con" class="box">
<h3>联系我们</h3>
</p>
<p id="job" class="box" style="height:680px">
<h3>人才招聘</h3>
</p>
</p>
</body>
</html>

JS 插件:scroll to

不用锚点也可以平滑滚动到页面的指定位置

. 代码如下:

<!DOCTYPE html>
<html >
<head>
<meta content="text/html; charset=utf-8" />
<title>ScrollTo:平滑滚动到页面指定位置</title>
<link rel="stylesheet" type="text/css" href="../css/main.css" />
<style type="text/css">
.nav{width:500px;margin:10px auto;}
.nav li{float:left; width:100px; height:24px; line-height:24px}
.box{height:500px}
.box h3{height:32px; line-height:32px; padding-left:20px; font-size:14px}
.clear{clear:both}
html,body,p,span,h1,h2,h3,h4,h5,h6,p,pre,a,code,em,img,small,strong,sub,sup,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}
a{color:#007bc4/*#424242*/; text-decoration:none;}
a:hover{text-decoration:underline}
ol,ul{list-style:none}
table{border-collapse:collapse;border-spacing:0}
body{height:100%; font:12px/18px "Microsoft Yahei", Tahoma, Helvetica, Arial, Verdana, "/5b8b/4f53", sans-serif; color:#51555C; background:#162934 url(../images/body_bg.gif) repeat-x}
img{border:none}
#main{width:910px; min-height:600px; margin:30px auto 0 auto; background:#fff; -moz-border-radius:12px;-khtml-border-radius: 12px;-webkit-border-radius: 12px; border-radius:12px;}
h2.top_title{margin:4px 20px; padding-top:15px; padding-left:20px; padding-bottom:10px; border-bottom:1px solid #d3d3d3; font-size:18px; color:#a84c10;}
</style>
<script type="text/javascript" src="https://jt.875.cn/js/jquery.js"></script>
<script type="text/javascript" src="https://jt.875.cn/js/scrollto.js"></script>
<script type="text/javascript">
$(function(){
$(".nav_pro").click(function(){
$.scrollTo('#pro',500);
});
$(".nav_news").click(function(){
$.scrollTo('#news',800);
});
$(".nav_ser").click(function(){
$.scrollTo('#ser',1000);
});
$(".nav_con").click(function(){
$.scrollTo('#con',1200);
});
$(".nav_job").click(function(){
$.scrollTo('#job',1500);
});
});
</script>
</head>
<body>
<p id="main">
<h2 class="top_title">ScrollTo:平滑滚动到页面指定位置</h2>
<ul class="nav">
<li><a href="#" class="nav_pro">产品展示</a></li>
<li><a href="#" class="nav_news">新闻中心</a></li>
<li><a href="#" class="nav_ser">服务支持</a></li>
<li><a href="#" class="nav_con">联系我们</a></li>
<li><a href="#" class="nav_job">人才招聘</a></li>
</ul>
<p class="clear"></p>
<p id="pro" class="box">
<h3>产品展示</h3>
</p>
<p id="news" class="box">
<h3>新闻中心</h3>
</p>
<p id="ser" class="box">
<h3>服务支持</h3>
</p>
<p id="con" class="box">
<h3>联系我们</h3>
</p>
<p id="job" class="box" style="height:680px">
<h3>人才招聘</h3>
</p>
</p>
</body>
</html>

JS 插件:scroll to

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

本文固定链接: http://www.js-code.com/js/js_1569.html