滚动页面直到某个高度 [英] Scroll page until some height

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

问题描述

 函数pageScroll()如何使用javascript滚动页面,直到滚动的高度将有一些预定义的像素数? ){
//下一行是伪代码:
if(window.ScrolledHeight!= SOME_NUM)
window.scrollBy(0,50);
}
scrolldelay = setTimeout('pageScroll()',100);

应该有一些逻辑检查。你可以帮助我,如何获得滚动的高度?

解决方案

您可以使用函数以外的变量来增加值每次运行50像素pageScroll,然后检查它是否等于或大于您要查找的值?

eg

  var scrollAmount = 0; 

函数pageScroll(){
window.scrollBy(0,50);
scrollAmount + = 50;
if(scrollAmount< 200){
scrolldelay = setTimeout('pageScroll()',100);
}
}

你也可以让函数接受一个你修改的参数,如果你不想使用全局变量。


how can I scroll the page with javascript until the scrolled height will be some predefined number of pixels?

function pageScroll() {
    // Next line is pseudocode:
    if (window.ScrolledHeight != SOME_NUM)
       window.scrollBy(0,50);
}
scrolldelay = setTimeout('pageScroll()',100);

There should be some logical checking of something. Could you help me, how to get scrolled height?

解决方案

Could you use a variable outside of the function that would increment the value by 50 pixels everytime pageScroll ran and then check to see if that is equal to or greater than the value you are looking for?

e.g.

var scrollAmount = 0;

function pageScroll() {
    window.scrollBy(0,50);
    scrollAmount += 50;
    if(scrollAmount < 200) {
        scrolldelay = setTimeout('pageScroll()',100);
    }
}

You could also make the function take in a parameter that you modify if you don't want to use the global variable.

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

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