滚动到页面加载之前 [英] scroll to before page load

查看:102
本文介绍了滚动到页面加载之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用javascript使页面加载200px。但我总是看到前面的1秒向前滚动。

I'm trying to make the page load 200px further down using javascript. But I always see 1 second of the top before is scrolls down.

vimoe这样做,尝试在页面加载后向上滚动, http://vimeo.com/49645156

vimoe does this, try scrolling up after the page is loaded, http://vimeo.com/49645156

margin-top:-200px .. Gives我这个效果,但我不能在保证金设置为负数后向上滚动。

margin-top:-200px.. Gives me this effect, but I cant' scroll up after margin is set with a negative number.

也许在页面出现之后制作一个改变身体边距的jquery解决方案加载,会有效吗?

Maybe make a jquery solution that changes the body margin-top after the page is loaded, will that work?

目前使用此脚本

function jumpScroll() {
window.scroll(0,200); // horizontal and vertical scroll targets

}

我只是调用这个脚本来自身体的onload。

I just call this script from the body with onload.

推荐答案

为什么不使用分部ID而不是给予边距?

Instead of giving margins, why don't use the division id?

我相信你已经给你想要在加载时显示在上面的部门提供了一个ID。

I am sure you have given a ID to the division which you want to show on top when loading.

只需使用div ID,如下所示:

just use the div ID, like this :

$(document).ready(function (){
    var div= $('#example'); // take your div id
    $(window).scrollTop(div.offset().top).scrollLeft(div.offset().left);
}

这篇关于滚动到页面加载之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆