如何自动向下滚动html页面? [英] how to automatically scroll down a html page?

查看:1521
本文介绍了如何自动向下滚动html页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在首页后开始每个网页约500像素,类似于此网站: http://unionstationdenver.com/

I'm trying to start each page after the homepage about 500px down, similar to this website: http://unionstationdenver.com/

您会注意到在首页之后查看页面时,您会自动向下滚动而不会通知,但是您可以向上滚动以再次显示特色滑块。

You'll notice when viewing pages after the homepage, you're automatically scrolled down without notice but you can than scroll up to revel the featured slider again.

我玩过scrolledHeight,但我不认为这是我需要的?

I've played with scrolledHeight but I dont think that is what I need????

基本上,我有一个特色部分位于我所有的内容页面之上,但是你向上滚动之前不能看到这个部分。任何帮助?

Basically I have a featured section that is on top of all my content pages, but you shouldn't be able to see this section until you scroll up. Any help?

推荐答案

您可以使用 .scrollIntoView()

示例:

document.getElementById( 'bottom' ).scrollIntoView();

演示: http://jsfiddle.net/ThinkingStiff/DG8yR/

脚本:

function top() {
    document.getElementById( 'top' ).scrollIntoView();    
};

function bottom() {
    document.getElementById( 'bottom' ).scrollIntoView();
    window.setTimeout( function () { top(); }, 2000 );
};

bottom();

HTML:

<div id="top">top</div>
<div id="bottom">bottom</div>

CSS:

#top {
    border: 1px solid black;
    height: 3000px;
}

#bottom {
    border: 1px solid red;
}

这篇关于如何自动向下滚动html页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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