标签:script height nim width jquery 滚动 UNC doc var
页面加载时滚动到指定的div
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="/Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
<body>
<div id="a1" style="width: 500px;height: 600px;background:#666;">
</div>
<div id="a2" style="width: 500px;height: 600px;background:red;">
</div>
<div id="a3" style="width: 500px;height: 600px;background:blue;">
</div>
<div id="a4" style="width: 500px;height: 600px;background:#999;">
</div>
<script type="text/javascript">
$(function(){
var scroll_offset = $("#a3").offset(); //得到这个div层的offset,包含两个值,top和left
$("body,html").animate({
scrollTop:scroll_offset.top //让body的scrollTop等于a3的top,就实现了滚动
},100);
})
</script>
</body>
</html>
标签:script height nim width jquery 滚动 UNC doc var
原文地址:https://www.cnblogs.com/whqbk/p/13268484.html