W3C home > Mailing lists > Public > www-style@w3.org > June 2012

[cssom-view] scrollMaxX/Y

From: Robert O'Callahan <robert@ocallahan.org>
Date: Fri, 22 Jun 2012 11:54:07 +1200
Message-ID: <CAOp6jLac6esZUQEBsbq6X-=o3g06qYhQiULXL4D92vQ65O5Ucg@mail.gmail.com>
To: www-style <www-style@w3.org>
Web authors want to detect when scrollable elements can be scrolled in a
given direction,
Often this means knowing what the maximum value is for
scrollLeft/scrollTop. You can estimate this using scrollWidth - clientWidth
and scrollHeight - clientHeight, but that can give a slightly wrong answer
due to rounding if you're doing subpixel layout. For example, an element
whose unrounded clientHeight is 1.4px and unrounded scrollHeight is 1.6px
would compute scrollWidth - clientWidth = 1 although in fact scrollTop's
maximum value is 0 (actually, whether scrollTop's maximum value is 0 or 1
depends on how the UA handles scrolling with subpixel rendering, but 0 is a
reasonable choice).

It would be simpler and less error-prone to simply have a DOM attribute
that returns the maximum values for scrollLeft/scrollTop. For the viewport,
Gecko has supported window.scrollMaxX/Y for a long time, but no-one else
has this as far as I know.

I propose adding scrollMaxX and scrollMaxY as read-only DOM attributes on
Element, returning the maximum possible values for scrollLeft and scrollTop
respectively. They would of course be 0 for non-scrollable elements.

For the bikeshedders out there, I think scrollLeftMax and scrollTopMax
would also be acceptable names.

“You have heard that it was said, ‘Love your neighbor and hate your enemy.’
But I tell you, love your enemies and pray for those who persecute you,
that you may be children of your Father in heaven. ... If you love those
who love you, what reward will you get? Are not even the tax collectors
doing that? And if you greet only your own people, what are you doing more
than others?" [Matthew 5:43-47]
Received on Thursday, 21 June 2012 23:54:40 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:39:00 UTC