dixonandmoe / rellax

Lightweight, vanilla javascript parallax library
https://dixonandmoe.com/rellax/
MIT License
7.04k stars 880 forks source link

Added support for NodeLists and HTMLCollections #226

Closed SimonGemmel closed 2 years ago

SimonGemmel commented 3 years ago

It is currently not possible to initialize with a list of elements. This change will make it possible to use a NodeList (querySelectorAll) or a HTMLCollection (getElementsByClassName / TagName / ...)

rikers commented 3 years ago

+1 for this quick win. Very usefull when working in a "components driven application" where each component can be associated some perticular JS logic.

in html: <div class="my-component" data-module="my-component>...</div>

In my-component.js:

export default {
    // Here, $el represents the div.
    init($el) {
            const rellaxes = $el.querySelectorAll('.rellax');
            this.rellax = new Rellax(rellaxes);
        }
}