Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update base #1

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bc68a0f
Add support for `duration` option in native mode
xavierfoucrier May 3, 2021
9126add
Update README.md
akkis Jul 8, 2021
aa77464
fix typo in 'Progressive playing animations' block of README
udovichenko Jul 13, 2021
c9e72ba
Merge remote-tracking branch 'upstream/master'
xavierfoucrier Sep 15, 2021
aa4d4d9
Prevent scrolling class to be applied on mouseup
xavierfoucrier Sep 15, 2021
e12c470
Merge pull request #347 from xavierfoucrier/fix/mouseup-scrolling-class
devenini Oct 21, 2021
037c8c4
Merge pull request #318 from akkis/patch-1
devenini Oct 21, 2021
c1326ea
Merge pull request #321 from udovichenko/fix-docs-typo
devenini Oct 21, 2021
53fa8b4
Fix scrollbar locks after scrolling with mousewheel. Resolved #310
devenini Oct 21, 2021
87454e2
Add disclaimer in README
devenini Oct 21, 2021
926c34d
Bump version in front-end demo
devenini Oct 21, 2021
55b8a89
4.1.3
devenini Oct 21, 2021
78934f1
Update package version in lock file
mcaskill Oct 27, 2021
ee2050b
Fix audited vulnerabilities in NPM lock file
mcaskill Oct 27, 2021
959f2f8
Apply Prettier formatting
mcaskill Oct 28, 2021
ca5bf7c
Fix Sass and PostCSS compilation
mcaskill Oct 28, 2021
e85499e
Update scripts and styles
mcaskill Oct 28, 2021
e324a2a
docs: fix simple typo, additionnal -> additional
timgates42 Nov 2, 2021
d2cb7e6
Prevent keyboard scrolling depending on activeElement type
devenini Feb 3, 2022
f28ef34
4.1.4
devenini Feb 3, 2022
0aab963
fix 404
MackenzieChoy Apr 23, 2022
9c55399
Merge pull request #365 from timgates42/bugfix_typo_additional
Jerek0 Apr 28, 2022
9d7deb9
Add blank target to locomotive.ca link
Jerek0 Apr 28, 2022
53d7a28
Merge pull request #423 from MackenzieChoy/patch-2
Jerek0 Apr 28, 2022
c07fe39
Update README.md
devenini May 30, 2023
8ac3990
Replace polyfill.io with Cloudflare
mcaskill Jun 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
[![](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! 😄


<p align="center">
<a href="https://github.com/locomotivemtl/locomotive-scroll">
<img src="https://user-images.githubusercontent.com/4596862/58807621-67aeec00-85e6-11e9-8e3a-3fe4123ee76c.png" height="140">
Expand All @@ -11,6 +22,8 @@

## Installation

> ⚠️ Scroll-hijacking is a controversial practice that can cause usability, accessibility, and performance issues. Please use responsibly.

```sh
npm install locomotive-scroll
```
Expand Down Expand Up @@ -179,7 +192,7 @@ scroll.on('call', func => {
| `destroy()` | Destroys the scroll events. | |
| `start()` | Restarts the scroll events. | |
| `stop()` | Stops the scroll events. | |
| `scrollTo(target, options)`| Scroll to a target. | <div>`target`: Defines where you want to scroll. Available values types are :<ul><li>`node` : a dom element</li><li>`string` : you can type your own selector, or use values `"top"` and `"bottom"` to reach scroll boundaries</li><li>`int` : An absolute scroll coordinate in pixels</li></ul></div><div>`options` (optional, _object_) : Settings object. Available values are: <ul><li>`offset` (_integer_) : Defines an offset from your target. E.g. `-100` if you want to scroll 100 pixels above your target</li><li>`callback` (_function_) : Called when scrollTo completes (note that it won't wait for lerp to stabilize)</li><li>`duration` (_integer_) : Defines the duration of the scroll animation in milliseconds. Defaults to `1000`<br>![Smooth only][smooth-only]</li><li>`easing` (_array_) : An `array` of 4 floats between 0 and 1 defining the bezier curve for the animation's easing. <br>Defaults to `[0.25, 0.00, 0.35, 1.00]`<br>See [http://greweb.me/bezier-easing-editor/example/](http://greweb.me/bezier-easing-editor/example/)<br>*Keep in mind this will also be affected by the lerp unless you set `disableLerp` to `true`*.<br>![Smooth only][smooth-only]</li><li>`disableLerp` (_boolean_) : Lerp effect won't be applied if set to `true`<br>![Smooth only][smooth-only]</li></ul> |
| `scrollTo(target, options)`| Scroll to a target. | <div>`target`: Defines where you want to scroll. Available values types are :<ul><li>`node` : a dom element</li><li>`string` : you can type your own selector, or use values `"top"` and `"bottom"` to reach scroll boundaries</li><li>`int` : An absolute scroll coordinate in pixels</li></ul></div><div>`options` (optional, _object_) : Settings object. Available values are: <ul><li>`offset` (_integer_) : Defines an offset from your target. E.g. `-100` if you want to scroll 100 pixels above your target</li><li>`callback` (_function_) : Called when scrollTo completes (note that it won't wait for lerp to stabilize)</li><li>`duration` (_integer_) : Defines the duration of the scroll animation in milliseconds. Defaults to `1000`<br>![Smooth only][smooth-only]</li><li>`easing` (_array_) : An `array` of 4 floats between 0 and 1 defining the bezier curve for the animation's easing. <br>Defaults to `[0.25, 0.00, 0.35, 1.00]`<br>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)<br>*Keep in mind this will also be affected by the lerp unless you set `disableLerp` to `true`*.<br>![Smooth only][smooth-only]</li><li>`disableLerp` (_boolean_) : Lerp effect won't be applied if set to `true`<br>![Smooth only][smooth-only]</li></ul> |

## Instance events

Expand All @@ -205,7 +218,7 @@ scroll.on('scroll', (args) => {
// ouput log example: 0.34
// gsap example : myGsapAnimation.progress(progress);
}
}
});
```


Expand All @@ -232,7 +245,7 @@ You can use your own or include these before our script.

```html
<script nomodule src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.6.0/polyfill.min.js" crossorigin="anonymous"></script>
<script nomodule src="https://polyfill.io/v3/polyfill.min.js?features=Object.assign%2CElement.prototype.append%2CNodeList.prototype.forEach%2CCustomEvent%2Csmoothscroll" crossorigin="anonymous"></script>
<script nomodule src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=Object.assign%2CElement.prototype.append%2CNodeList.prototype.forEach%2CCustomEvent%2Csmoothscroll" crossorigin="anonymous"></script>
```

## Who's using Locomotive Scroll?
Expand Down
10 changes: 6 additions & 4 deletions build/styles.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import gulp from 'gulp';
import sass from 'gulp-sass';
import gulpSass from 'gulp-sass';
import autoprefixer from 'gulp-autoprefixer';
import header from 'gulp-header';
import merge from 'merge-stream';
import nodeSass from 'node-sass';
import paths from '../mconfig.json';
import pkg from '../package.json';
import error from './error.js';
import { server } from './serve.js';

const sass = gulpSass(nodeSass);

function styles() {
const files = [
{
Expand All @@ -23,10 +26,9 @@ function styles() {
const streams = files.map((file) => {
return gulp
.src(file.src + '**/*.scss')
.pipe(sass())
.on('error', function(err) {
.pipe(sass().on('error', function (err) {
error(this, err, 'stack');
})
}))
.pipe(autoprefixer({
cascade: false
}))
Expand Down
2 changes: 1 addition & 1 deletion dist/locomotive-scroll.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! locomotive-scroll v4.1.1 | MIT License | https://github.com/locomotivemtl/locomotive-scroll */
/*! locomotive-scroll v4.1.3 | MIT License | https://github.com/locomotivemtl/locomotive-scroll */
html.has-scroll-smooth {
overflow: hidden; }

Expand Down
30 changes: 24 additions & 6 deletions dist/locomotive-scroll.esm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* locomotive-scroll v4.1.1 | MIT License | https://github.com/locomotivemtl/locomotive-scroll */
/* locomotive-scroll v4.1.3 | MIT License | https://github.com/locomotivemtl/locomotive-scroll */
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
Expand Down Expand Up @@ -1340,7 +1340,7 @@ var _default$1 = /*#__PURE__*/function (_Core) {

window.scrollTo({
top: offset,
behavior: 'smooth'
behavior: options.duration === 0 ? 'auto' : 'smooth'
});
}
}, {
Expand Down Expand Up @@ -2153,6 +2153,9 @@ var _default$2 = /*#__PURE__*/function (_Core) {
key: "stopScrolling",
value: function stopScrolling() {
cancelAnimationFrame(this.checkScrollRaf); // Prevent checkScroll to continue looping
//Pevent scrollbar glitch/locking

this.startScrollTs = undefined;

if (this.scrollToRaf) {
cancelAnimationFrame(this.scrollToRaf);
Expand Down Expand Up @@ -2202,11 +2205,17 @@ var _default$2 = /*#__PURE__*/function (_Core) {
break;

case keyCodes$1.UP:
this.instance.delta[this.directionAxis] -= 240;
if (this.isActiveElementScrollSensitive()) {
this.instance.delta[this.directionAxis] -= 240;
}

break;

case keyCodes$1.DOWN:
this.instance.delta[this.directionAxis] += 240;
if (this.isActiveElementScrollSensitive()) {
this.instance.delta[this.directionAxis] += 240;
}

break;

case keyCodes$1.PAGEUP:
Expand All @@ -2226,7 +2235,7 @@ var _default$2 = /*#__PURE__*/function (_Core) {
break;

case keyCodes$1.SPACE:
if (!(document.activeElement instanceof HTMLInputElement) && !(document.activeElement instanceof HTMLTextAreaElement)) {
if (this.isActiveElementScrollSensitive()) {
if (e.shiftKey) {
this.instance.delta[this.directionAxis] -= window.innerHeight;
} else {
Expand All @@ -2248,6 +2257,11 @@ var _default$2 = /*#__PURE__*/function (_Core) {
this.checkScroll();
this.html.classList.add(this.scrollingClass);
}
}, {
key: "isActiveElementScrollSensitive",
value: function isActiveElementScrollSensitive() {
return !(document.activeElement instanceof HTMLInputElement) && !(document.activeElement instanceof HTMLTextAreaElement) && !(document.activeElement instanceof HTMLButtonElement) && !(document.activeElement instanceof HTMLSelectElement);
}
}, {
key: "checkScroll",
value: function checkScroll() {
Expand Down Expand Up @@ -2511,7 +2525,11 @@ var _default$2 = /*#__PURE__*/function (_Core) {
key: "releaseScrollBar",
value: function releaseScrollBar(e) {
this.isDraggingScrollbar = false;
this.html.classList.add(this.scrollingClass);

if (this.isScrolling) {
this.html.classList.add(this.scrollingClass);
}

this.html.classList.remove(this.draggingClass);
}
}, {
Expand Down
30 changes: 24 additions & 6 deletions dist/locomotive-scroll.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* locomotive-scroll v4.1.1 | MIT License | https://github.com/locomotivemtl/locomotive-scroll */
/* locomotive-scroll v4.1.3 | MIT License | https://github.com/locomotivemtl/locomotive-scroll */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
Expand Down Expand Up @@ -1346,7 +1346,7 @@

window.scrollTo({
top: offset,
behavior: 'smooth'
behavior: options.duration === 0 ? 'auto' : 'smooth'
});
}
}, {
Expand Down Expand Up @@ -2159,6 +2159,9 @@
key: "stopScrolling",
value: function stopScrolling() {
cancelAnimationFrame(this.checkScrollRaf); // Prevent checkScroll to continue looping
//Pevent scrollbar glitch/locking

this.startScrollTs = undefined;

if (this.scrollToRaf) {
cancelAnimationFrame(this.scrollToRaf);
Expand Down Expand Up @@ -2208,11 +2211,17 @@
break;

case keyCodes$1.UP:
this.instance.delta[this.directionAxis] -= 240;
if (this.isActiveElementScrollSensitive()) {
this.instance.delta[this.directionAxis] -= 240;
}

break;

case keyCodes$1.DOWN:
this.instance.delta[this.directionAxis] += 240;
if (this.isActiveElementScrollSensitive()) {
this.instance.delta[this.directionAxis] += 240;
}

break;

case keyCodes$1.PAGEUP:
Expand All @@ -2232,7 +2241,7 @@
break;

case keyCodes$1.SPACE:
if (!(document.activeElement instanceof HTMLInputElement) && !(document.activeElement instanceof HTMLTextAreaElement)) {
if (this.isActiveElementScrollSensitive()) {
if (e.shiftKey) {
this.instance.delta[this.directionAxis] -= window.innerHeight;
} else {
Expand All @@ -2254,6 +2263,11 @@
this.checkScroll();
this.html.classList.add(this.scrollingClass);
}
}, {
key: "isActiveElementScrollSensitive",
value: function isActiveElementScrollSensitive() {
return !(document.activeElement instanceof HTMLInputElement) && !(document.activeElement instanceof HTMLTextAreaElement) && !(document.activeElement instanceof HTMLButtonElement) && !(document.activeElement instanceof HTMLSelectElement);
}
}, {
key: "checkScroll",
value: function checkScroll() {
Expand Down Expand Up @@ -2517,7 +2531,11 @@
key: "releaseScrollBar",
value: function releaseScrollBar(e) {
this.isDraggingScrollbar = false;
this.html.classList.add(this.scrollingClass);

if (this.isScrolling) {
this.html.classList.add(this.scrollingClass);
}

this.html.classList.remove(this.draggingClass);
}
}, {
Expand Down
2 changes: 1 addition & 1 deletion dist/locomotive-scroll.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/locomotive-scroll.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/dist/scripts/main.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/dist/styles/main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/horizontal.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h1>
</div>

<script nomodule src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.6.0/polyfill.min.js" crossorigin="anonymous"></script>
<script nomodule src="https://polyfill.io/v3/polyfill.min.js?features=Object.assign%2CElement.prototype.append%2CNodeList.prototype.forEach%2CCustomEvent%2Csmoothscroll" crossorigin="anonymous"></script>
<script nomodule src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=Object.assign%2CElement.prototype.append%2CNodeList.prototype.forEach%2CCustomEvent%2Csmoothscroll" crossorigin="anonymous"></script>

<script src="dist/scripts/main.js"></script>
</body>
Expand Down
8 changes: 4 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
<div class="o-layout">
<div class="o-layout_item u-1/2" data-scroll data-scroll-direction="horizontal" data-scroll-speed="-2" data-scroll-position="top" data-scroll-target="#header">
<span class="u-label c-header_heading_label">
<a href="/">
<a href="https://locomotive.ca" target="_blank" rel="noopener noreferrer">
Locomotive.ca
</a>
</span>
</div>
<div class="o-layout_item u-1/2" data-scroll data-scroll-direction="horizontal" data-scroll-speed="2" data-scroll-position="top" data-scroll-target="#header">
<div class="u-text-right">
<p class="u-label c-header_heading_label">
v4 – Edition
v4.x – Edition
</p>
</div>
</div>
Expand All @@ -56,7 +56,7 @@ <h1 class="c-header_title o-h1" data-scroll>
<span data-scroll data-scroll-speed="2" data-scroll-position="top">Scroll</span>
</span>
<span class="c-header_title_line -version u-white">
<span class="o-h1" data-scroll data-scroll-speed="3" data-scroll-position="top" data-scroll-delay="0.05">v</span><span class="o-h1" data-scroll data-scroll-speed="5" data-scroll-position="top" data-scroll-delay="0.05">4</span><span class="o-h1" data-scroll data-scroll-speed="2" data-scroll-position="top" data-scroll-delay="0.05">.</span><span class="o-h1" data-scroll data-scroll-speed="4" data-scroll-position="top" data-scroll-delay="0.05">0</span>
<span class="o-h1" data-scroll data-scroll-speed="3" data-scroll-position="top" data-scroll-delay="0.05">v</span><span class="o-h1" data-scroll data-scroll-speed="5" data-scroll-position="top" data-scroll-delay="0.05">4</span><span class="o-h1" data-scroll data-scroll-speed="2" data-scroll-position="top" data-scroll-delay="0.05">.</span><span class="o-h1" data-scroll data-scroll-speed="4" data-scroll-position="top" data-scroll-delay="0.05">X</span>
</span>
</h1>
<hr class="c-header_line" data-scroll data-scroll-offset="100" />
Expand Down Expand Up @@ -451,7 +451,7 @@ <h1 class="o-title" data-scroll>
</div>

<script nomodule src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.6.0/polyfill.min.js" crossorigin="anonymous"></script>
<script nomodule src="https://polyfill.io/v3/polyfill.min.js?features=Object.assign%2CElement.prototype.append%2CNodeList.prototype.forEach%2CCustomEvent%2Csmoothscroll" crossorigin="anonymous"></script>
<script nomodule src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=Object.assign%2CElement.prototype.append%2CNodeList.prototype.forEach%2CCustomEvent%2Csmoothscroll" crossorigin="anonymous"></script>

<script src="dist/scripts/main.js"></script>
</body>
Expand Down
Loading