Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit 69ecd83

Browse files
committed
add option to block elements from scrolling page when hovered
1 parent 6ed2fc6 commit 69ecd83

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,15 @@ Passed as an object through to the ASScroll constructor. Defaults shown next to
9696
| `disableRaf` | `Boolean` | `false` | Disable internal requestAnimationFrame loop in order to use an external one |
9797
| `disableResize` | `Boolean` | `false` | Disable internal resize event on the window in order to use an external one |
9898
| `limitLerpRate` | `Boolean` | `true` | Match lerp speed on >60Hz displays to that of a 60Hz display |
99+
| `blockScrollClass` | `String` | `.asscroll-block` | Add this to elements that should prevent the page from scrolling whilst hovered. Useful for scrollable elements (with `overflow`) within the ASScroll page |
99100

100101
## Methods
101102

102103
`enable( restore = false, reset = false, newTarget = false, horizontalScroll = false )` - Enable scroll
103104

104105
- `restore` - restores the previous scroll position when `disable()` was last called
105106
- `reset` - force resetting scroll position to 0
106-
- `newTarget` - pass in a selected DOM node to set a new scroll target i.e. when loading in a new page via PJAX.
107+
- `newTarget` - pass in a selected DOM node to set a new scroll target i.e. when dynamically loading in a new page via AJAX.
107108
- `horizontalScroll` - set to true if you want the content to scroll horizontally
108109

109110
`disable()` - Disable scroll

src/Scroll.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ export default class Scroll {
185185
this.scrollTargets = newTargets.length ? newTargets : [newTargets]
186186
this.scrollTargetsLength = this.scrollTargets.length
187187
}
188+
189+
!this.scrollBlockElements && this.updateScrollBlockElements()
188190

189191
this.iframes = this.scrollContainer.querySelectorAll('iframe')
190192

@@ -270,6 +272,17 @@ export default class Scroll {
270272
}
271273
}
272274

275+
updateScrollBlockElements() {
276+
this.scrollBlockElements = document.querySelectorAll(this.options.blockScrollClass)
277+
for (let i = 0; i < this.scrollBlockElements.length; i++) {
278+
this.scrollBlockElements[i].addEventListener('wheel', this.blockScrollEvent)
279+
}
280+
}
281+
282+
blockScrollEvent(e) {
283+
e.stopPropagation()
284+
}
285+
273286
toggleFixedContainer() {
274287
this.scrollContainer.style.position = 'static'
275288
const scrollPos = this.smoothScrollPos

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export default class ASScroll {
1818
disableOnTouch = true,
1919
disableRaf = false,
2020
disableResize = false,
21-
limitLerpRate = true
21+
limitLerpRate = true,
22+
blockScrollClass = '.asscroll-block'
2223
} = {} ) {
2324

2425
E.bindAll(this, ['enable', 'disable', 'on', 'scrollTo', 'onRaf', 'onResize'])
@@ -39,7 +40,8 @@ export default class ASScroll {
3940
scrollbarStyles,
4041
disableNativeScrollbar,
4142
disableOnTouch,
42-
limitLerpRate
43+
limitLerpRate,
44+
blockScrollClass
4345
})
4446

4547
}

0 commit comments

Comments
 (0)