js 在页面中跳转到指定位置

1.页面中代码
<div style="left:98%;top:50%;border: 1px solid #438EB9;position: fixed;width:100px;margin-left:-100px;heigth:80px;">
			<div class="hover" style="margin-top:4px;text-align:center;cursor:pointer;" onclick="scrollTo('page1')">产品信息</div>
			<div class="hover" style="margin-top:4px;text-align:center;cursor:pointer;" onclick="scrollTo('page2')">单件信息</div>
			<div class="hover" style="margin-top:4px;text-align:center;cursor:pointer;" onclick="scrollTo('page3')">产品图片</div>
			<div class="hover" style="margin-top:4px;margin-bottom:4px;text-align:center;cursor:pointer;" onclick="scrollTo('page4')">产品说明书</div>
		</div>


2.跳转对应的函数
function scrollTo(id){
		    jQuery("html, body").animate({
		      scrollTop: jQuery("#"+id).offset().top }, {duration: 500,easing: "swing"});
		}

猜你喜欢

转载自forlan.iteye.com/blog/2397452