Z
Z
zwezew2018-10-16 17:23:05
JavaScript
zwezew, 2018-10-16 17:23:05

Disable Slick auto-scroll if slider is scrolled off screen?

The client issued an edit, from which he slightly precipitated.
It is required that in a slider scrolled off the screen, for example, more than 500px, auto-scrolling is disabled.

How can this be done at all?

$('[data-slick]').each(function () {
        var slider = $(this),
            autoplay;

        $(window).on('load scroll', function() {
            var sliderHeight = slider.height(),
                windowHeight = window.screen.height,
                scroll = $(window).scrollTop(),
                visibleZone = sliderHeight - scroll;

            if (visibleZone <= 100) {
                autoplay = false;
            } else {
                autoplay = true;
            }
        });
        
        slider.slick({
            slidesToShow: 1,
            slidesToScroll: 1,
            infinite: true,
            autoplay: autoplay,
            autoplaySpeed: 5000,
            arrows: false,
            dots: true,
        });
    });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor, 2018-10-16
@futior

Remember the slider number when scrolling, when scrolling back, set the active slide (slickGoTo) to slick this number.

M
msdos-x86, 2018-10-16
@msdos-x86

you get paid money not us
so good luck

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question