stutrek / scrollmonitor

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

Newb Question Not Issue #88

Closed dgerding closed 5 years ago

dgerding commented 5 years ago

Sorry to ask but when you say:

var scrollMonitor = require("scrollmonitor"); // if you're old school you can use the scrollMonitor 
                                                                       // global.

What's the right way to create the scrollMonitor instance without using require?

Thanks if your able to help and thanks regardless for cool code.

fedetibaldo commented 5 years ago

As the following comment implies, in case you are not using any module bundler (e.g. webpack, parcel...) which resolves the requires / imports for you, you should use the globally available variable (window.scrollMonitor I guess). Please mind that since the latter is attached to the window object, you don’t need to specify window. at all. Just act as if the import was already done and reference scrollMonitor with no worries.

fedetibaldo commented 5 years ago

One thing I forgot to mention: module bundlers inject dependencies where needed, but if you are not using any, you should always import the script you are referencing either in the <head> or at the end of the <body>.

dgerding commented 5 years ago

Thanks Federico, that helped!