stutrek / scrollmonitor

A simple and fast API to monitor elements as you scroll

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

question

robbisy opened this issue · comments

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 );

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.

@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 ?