当打开这个页面的时候,页面滑动跳转到距离页面顶部100px的id="scroll"的div处,
每次刷新页面的时候也会跳转到此处,这样的jQuery怎么写?谁能告诉我?谢谢!
页面body代码如下:
<body>
<div style="background-color:#ff6600; height:100px;">
</div>
<div id="scroll" style="height:1500px;">
滚动到这里
</div>
</body>
需要准备的材料分别有:电脑、html编辑器、浏览器。
1、首先,打开html编辑器,新建html文件,例如:index.html,并引入jquery。
2、在index.html中的<script>标签,输入jquery代码:
var container = $('body');
var scrollTo = $('#scroll');
container.scrollTop(
scrollTo.offset().top - container.offset().top + container.scrollTop()
);
container.animate({
scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop()
});
3、浏览器运行index.html页面,此时刷新页面会自动滑动到指定位置。
有 jQuery 一句就足够了。第一个 scrollTop(0) 还原到顶端,防止刷新位置不变。
没测试,你试试看吧
追问js没有起作用,不过还是谢谢了。
追答楼上厉害,原来动画这个本身支持滚动条动画啊
直接复制加载JQ。。看下效果。。不知道是不是你要的效果。。
不是我想要的,不过还是谢谢啦