Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Fix Scroller Gadget #188

Merged
merged 3 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/Gadgets/Compatibility/Scroller/Scroller.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.scroller-item {scroll-behavior: smooth;}
32 changes: 15 additions & 17 deletions src/Gadgets/Compatibility/Scroller/Scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,24 @@
/* <nowiki> */
"use strict";

function Scroller(element){
function Scroller(element) {
function wheelHandler(e) {
if (e.deltaY && !e.deltaX) {
e.preventDefault()
requestAnimationFrame(() => {
element.scrollBy(e.deltaY, 0)
})
e.preventDefault();
requestAnimationFrame(function () {
element.scrollBy(e.deltaY, 0);
});
}
}

element.addEventListener('wheel', wheelHandler)
element.style.scrollSnapType = 'none'
return () => {
element.removeEventListener('wheel', wheelHandler)
element.style.scrollSnapType = ''
}
element.addEventListener('wheel', wheelHandler);
element.style.scrollSnapType = 'none';
return function () {
element.removeEventListener('wheel', wheelHandler);
element.style.scrollSnapType = '';
};
}

const scroller_containers = document.getElementsByClassName('scroller-container')
for (let index = 0; index < scroller_containers.length; index++) {
const element = scroller_containers[index];
Scroller(element)
var scroller_containers = document.getElementsByClassName('scroller-container');
for (var index = 0; index < scroller_containers.length; index++) {
var element = scroller_containers[index];
Scroller(element);
}