查找页面的最大滚动位置

编程入门 行业动态 更新时间:2024-10-21 13:41:26
本文介绍了查找页面的最大滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将页面的主体做成200%高,这样它就可以在屏幕上放两次.使用javascript时,滚动时会一直滚动到顶部或底部.为此,我需要找出任何浏览器或屏幕尺寸下页面的最低滚动点,以便在到达该页面时停止滚动.

I have made the body of the page 200% tall so that it fits on a screen twice. Using javascript I am making it keep scrolling to the top or bottom when you scroll. For this, I need to find out the lowest scroll point of the page on any browser or screen size so that it stops when it gets there.

请不要使用JQuery. 谢谢.

No JQuery please. Thank you.

我的代码:(它仍在组合中,因此需要一些工作)

My code: (it is still being put together so needs a bit of work)

function getScrollXY() { var x = 0, y = 0; if( typeof( window.pageYOffset ) == 'number' ) { // Netscape x = window.pageXOffset; y = window.pageYOffset; } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { // DOM x = document.body.scrollLeft; y = document.body.scrollTop; } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { // IE6 standards compliant mode x = document.documentElement.scrollLeft; y = document.documentElement.scrollTop; } return [x, y]; } function scrollup() { if (xy[1] > 0) { window.scrollBy(0,-100); setTimeout(scrollup,200); } else { null; } } function scrolldown() { if (xy[1] < ) { window.scrollBy(0,100); setTimeout(scrolldown,200); } else { null; } } function dothescroll() { var xy = getScrollXY(); var y = xy[1]; setTimeout(function(){ if (xy[1] > y) { scrollup(); } else { scrolldown(); } },200); }

推荐答案

这是跨浏览器兼容的版本:

This is the cross browser compatible version:

var limit = Math.max( document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight );

更多推荐

查找页面的最大滚动位置

本文发布于:2023-10-08 01:37:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471138.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   页面

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!