stutrek / scrollmonitor

A simple and fast API to monitor elements as you scroll
MIT License
3.3k stars 243 forks source link

question #78

Closed robbisy closed 6 years ago

robbisy commented 6 years ago

Hi I have multiple elements which have the same animation. Can I use getElementsByClassName instead of getElementById like this

var myElements = document.getElementsByClassName("itemsToWatch");

var elementsWatcher = scrollMonitor.create( myElements );

stutrek commented 6 years ago

Sorry, there is no function to create many watchers. You can do this if you have a polyfill for Array.from

var watchers = Array.from(myElements).map(scrollMonitor.create)

This will also work with document.querySelector.

robbisy commented 6 years ago

@stutrek Thanks for your answer I don't understand

This will also work with document.querySelector.

I thought that querySelector returns the first element that matches with the class. How could I create many watchers with document.querySelector ?