glide icon indicating copy to clipboard operation
glide copied to clipboard

Allow horizontal scroll using mouse?

Open simplenotezy opened this issue 5 years ago • 3 comments

I would like to enable horizontal scrolling using the mouse; is that possible? Currently I can only go to next slide using buttons, or dragging, but I'd like to be able to scroll left or right using my mouse

simplenotezy avatar Oct 29 '20 12:10 simplenotezy

If it is your scroll wheel, maybe you could trigger next/prev slide based on your own listener for mouse wheel.

clieee avatar Oct 31 '20 22:10 clieee

There's no scroll event happening. Because in Glide.js there's no overflow. So that won't work

mawiswiss avatar Jun 21 '23 08:06 mawiswiss

As close as I could get for now:

glideDiv.addEventListener("wheel", throttle((e) => {
    e.stopPropagation();

    if (e.deltaY < -3) {
        // up
        glide.go("<");
    }
    if (e.deltaY > 3) {
        // down
        glide.go(">");
    }
    return false;
}, 50), { passive: true });

function throttle(mainFunction, delay) {
    let timerFlag = null; // Variable to keep track of the timer

    // Returning a throttled version 
    return (...args) => {
        if (timerFlag === null) { // If there is no timer currently running
            mainFunction(...args); // Execute the main function 
            timerFlag = setTimeout(() => { // Set a timer to clear the timerFlag after the specified delay
                timerFlag = null; // Clear the timerFlag to allow the main function to be executed again
            }, delay);
        }
    };
}

alvipeo avatar Jan 29 '24 15:01 alvipeo