W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2017

Re: Suggestion: Element.scrollParent

From: Ori Adam <oria@blossom-kc.com>
Date: Thu, 29 Jun 2017 17:30:52 +0300
Message-ID: <CAP9L1qc96tw2exDR7Uukuje8hSLc1qZd+Jfpt0OdAGkbznZr2w@mail.gmail.com>
To: Mark <mark@heyimmark.com>
Cc: www-dom@w3.org
Just noticed that I haven't answered. Sorry for the delay

Use cases are when an element needs to be scroll-aware, and the container
can be many different elements.
Some examples:
- Sticky positioning
- Load sub elements when element becomes visible in scroll
- Animate element when visible in scroll
- Pause animations when element is out of sight
- Do something when scrolling to bottom

scrollParents array for nested scroll-enabled containers might be useful as
well, tough it can be easily achieved by recursively calling
scrollParent.scrollParent.scrollParent...

I prepared one example for a use of scrollParent:
https://jsfiddle.net/oriadam/n53asLs2


On Mon, Jun 12, 2017 at 4:41 PM, Mark <mark@heyimmark.com> wrote:

> Sounds like a cool feature. What are the use-cases? I'm genuinely curious
> as I've never came across a situation where I've needed this. Are there not
> any cases where there may be two parents in the hierarchy and you don't
> want the closest, but the one after it? Also, a more specific name would be
> better like "closestScrollParent" or similar. "scrollParent" is vague since
> there could be multiple "scrollParent"s technically.
>
> On Mon, Jun 12, 2017 at 8:14 AM Ori Adam <oria@blossom-kc.com> wrote:
>
>> Suggestion: Element.scrollParent
>> Returns the closest element which controls the position of current
>> element with a scroll.
>>
>>
>> This feature very useful in many cases, easy for browsers to implement
>> and hard for plugins such as jQueryUI to get it right.
>>
>> Thanks
>>
>>
>>
Received on Thursday, 29 June 2017 14:31:47 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 29 June 2017 14:31:55 UTC