最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I determine the max scroll position in different browsers with different line-height andor padding? - Stack

programmeradmin3浏览0评论

Is there a way to determine the max scroll position for every browser, without actually scrolling to the end and reading this position?

Taken a container div with a fixed height and overflow. Several div elements in the container whose sum of heights is bigger then the height of the container.

There is a max scroll position (y) which I thought is simply the container-height minus the total items-height. This seems to be true until the line-height of the container is larger then the height of the items. If this is the case, it seems that every browser determines the max scroll position differently.

With padding it got even worse, some browsers add the top padding, some browsers add both top and bottom padding.

See this fiddle for example. Play around with the container line-height and the div.item height.

Is there a way to determine the max scroll position for every browser, without actually scrolling to the end and reading this position?

Taken a container div with a fixed height and overflow. Several div elements in the container whose sum of heights is bigger then the height of the container.

There is a max scroll position (y) which I thought is simply the container-height minus the total items-height. This seems to be true until the line-height of the container is larger then the height of the items. If this is the case, it seems that every browser determines the max scroll position differently.

With padding it got even worse, some browsers add the top padding, some browsers add both top and bottom padding.

See this fiddle for example. Play around with the container line-height and the div.item height.

Share Improve this question asked Dec 27, 2012 at 11:56 WoomlaWoomla 1991 gold badge4 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

I only have the ability to test in a handful of browsers, but I think what you are looking for is:

elm.scrollHeight - elm.clientHeight

Shown in an updated jsFiddle.

Take a look at this How to find the HTML element Scrollable Height and width using JQuery ?, this shows how to get the scrollable height and width, and there is some related posts regarding element scroll how to check if the scrollbars are currently visible? and how to determine if the vertical and horizontal scrollbars reaches the edges?. and there are more FAQs available and i hope this will help you !.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论