[![](https://img.shields.io/npm/v/locomotive-scroll)](https://www.npmjs.com/package/locomotive-scroll)
[![](https://img.shields.io/npm/dm/locomotive-scroll)](https://www.npmjs.com/package/locomotive-scroll)
> 🚀 **Locomotive Scroll v5 Beta Release**
>
> Try out the beta version of Locomotive Scroll v5!
>
> 🔗 [Click here to try Locomotive Scroll v5 Beta](https://github.com/locomotivemtl/locomotive-scroll/tree/v5-beta)
>
> Your feedback is valuable during this beta testing phase. If you encounter any issues or have suggestions, please [open an issue](https://github.com/locomotivemtl/locomotive-scroll/issues/new?labels=v5&template=bug_report.md).
>
> Happy scrolling! 😄
Detection of elements in viewport & smooth scrolling with parallax effects.
## Installation
> ⚠️ Scroll-hijacking is a controversial practice that can cause usability, accessibility, and performance issues. Please use responsibly.
```sh
npm install locomotive-scroll
```
## Usage
### Basic
With simple detection.
#### HTML
```html
`options` (optional, _object_) : Settings object. Available values are:
- `offset` (_integer_) : Defines an offset from your target. E.g. `-100` if you want to scroll 100 pixels above your target
- `callback` (_function_) : Called when scrollTo completes (note that it won't wait for lerp to stabilize)
- `duration` (_integer_) : Defines the duration of the scroll animation in milliseconds. Defaults to `1000`
![Smooth only][smooth-only] - `easing` (_array_) : An `array` of 4 floats between 0 and 1 defining the bezier curve for the animation's easing.
Defaults to `[0.25, 0.00, 0.35, 1.00]`
See [https://greweb.me/2012/02/bezier-curve-based-easing-functions-from-concept-to-implementation](https://greweb.me/2012/02/bezier-curve-based-easing-functions-from-concept-to-implementation)
*Keep in mind this will also be affected by the lerp unless you set `disableLerp` to `true`*.
![Smooth only][smooth-only] - `disableLerp` (_boolean_) : Lerp effect won't be applied if set to `true`
![Smooth only][smooth-only]
|
## Instance events
| Event | Arguments | Description |
| -------- | --------- | --------------------------------------------------------------------- |
| `scroll` | `obj` | Returns scroll instance (position, limit, speed, direction and current in-view elements). |
| `call` | `func` | Trigger if in-view. Returns your `string` or `array` if contains `,`. |
## Progressive playing animations example (like gsap)
All `data-scroll` elements have a progress value.
In the on scroll event you can get all current in-view elements.
#### HTML
```html
Hey
```
#### JS
```js
scroll.on('scroll', (args) => {
// Get all current elements : args.currentElements
if(typeof args.currentElements['hey'] === 'object') {
let progress = args.currentElements['hey'].progress;
console.log(progress);
// ouput log example: 0.34
// gsap example : myGsapAnimation.progress(progress);
}
});
```
## Dependencies
| Name | Description |
| ---------------- | ------------------------------------------------------------------ |
| [Virtual Scroll] | Custom scroll event with inertia/momentum. |
| [modularScroll] | Elements in viewport detection. Forked from it, not a dependency. |
| [bezier-easing] | Allows to define an easing to `scrollTo` movement |
[instance events]: #instance-events
[Virtual Scroll]: https://github.com/ayamflow/virtual-scroll
[modularScroll]: https://github.com/modularorg/modularscroll
[bezier-easing]: https://github.com/gre/bezier-easing
## Browser support
Works on most modern browsers. Chrome, Firefox, Safari, Edge...
To get IE 11 support, you need polyfills.
You can use your own or include these before our script.
```html
```
## Who's using Locomotive Scroll?
- [thierrychopain.com](https://thierrychopain.com/)
- [clmt.paris](https://clmt.paris/)
- [miragefestival.com/2020](https://www.miragefestival.com/2020/)
- [mazellier.design](https://www.mazellier.design/)
- [ccccontemple.com](https://ccccontemple.com/)
- [abhishekjha.me/muteza](https://abhishekjha.me/muteza/)
- [normal.studio](https://normal.studio/en/)
- [mixlegno.com](https://www.mixlegno.com/)
- [nfq.group](https://nfq.group/)
- [works.studio](https://works.studio/)
- [beangels.eu](https://www.beangels.eu/)
- [izakaya-caen.fr](https://www.izakaya-caen.fr/)
- [white-elephant.fr](https://www.white-elephant.fr/)
- [henge07.com](https://www.henge07.com/)
- [loirevalleylodges.com](https://loirevalleylodges.com/)
## Related
- [Locomotive Boilerplate 🚂](https://github.com/locomotivemtl/locomotive-boilerplate)
[smooth-only]: https://img.shields.io/badge/smooth-only-blue