Window Slider
A NodeJS module providing a sliding window function for arrays.
This can be useful when for instance implementing a image slideshow and you only want to load a say three images at a time.
Installation
NPM
npm install --save window-slider
Bower
bower install --save window-slider
Examples
In NodeJS
const windowSlider = ; const window = ; // Default window size is 3 items// and start index is 0console // [1, 2, 3] // You can move the window rightconsole // [2, 3, 4]console // [3, 4, 1] // You can reset the windowwindow;console // [1, 2, 3] // And you can move the window leftconsole // [4, 1, 2]console // [3, 4, 1] // You can retrieve a copy of the original arrayconsole // [1, 2, 3, 4, 5] // You can also specify the window size and start indexconst window2 = ; console // [2, 3]
In the Browser
// The module is exported as `WindowSlider` and works// as in the Node example above. var win = ; console // [1, 2, 3]console // [2, 3, 4]console // [3, 4, 1] // etc...
See tests for more elaborate examples.