Skip to content

Enable horizontal scrolling on slider #1094

Answered by Dekadinious
Dekadinious asked this question in Q&A
Discussion options

You must be logged in to vote

For anyone stumbling upon this, I solved it using the following code. The function should be passed the element to be scrollable and the Splide-instance. It could probably be solved better, but it works.

function allowSidewaysScroll(element, splide) {
        let debounceDelay = 500;
        let lastScrollTime = Date.now();

        //Add horizontal scrolling support to splide sliders
        element.addEventListener('wheel', function (event) {

            if (event.ctrlKey) {
                return; // Exit the function if Ctrl key is held
            }

            let deltaX = event.deltaX;
            let deltaY = event.deltaY;

            //Windows shift-scroll
            if (even…

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@lvigerust
Comment options

@Dekadinious
Comment options

Answer selected by Dekadinious
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants