×

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

作者:Terry2017.02.14来源:Web前端之家浏览:8892评论:0
关键词:JQueryJS
不用锚点也可以平滑滚动到页面的指定位置
复制代码 代码如下:

<!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,div,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="http://jt.875.cn/js/jquery.js"></script>
<script type="text/javascript" src="http://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>
<div 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>
<div class="clear"></div>
<div id="pro" class="box">
<h3>产品展示</h3>
</div>
<div id="news" class="box">
<h3>新闻中心</h3>
</div>
<div id="ser" class="box">
<h3>服务支持</h3>
</div>
<div id="con" class="box">
<h3>联系我们</h3>
</div>
<div id="job" class="box" style="height:680px">
<h3>人才招聘</h3>
</div>
</div>
</body>
</html>

JS 插件:scroll to

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/svg1487001600846.html

网友评论文明上网理性发言已有0人参与

发表评论: