I am facing an issue with achieving a specific effect on my website. I have implemented carousels, and I want them to start scrolling when the page is scrolled to them (halting page scroll), and once all slides have been viewed, resume page scrolling.
var slider = $('.slider');
$('.slider').slick({
dots: false,
vertical: true,
arrows: false,
variableWidth: false,
});
slider.on('wheel', (function(e) {
e.preventDefault();
if (e.originalEvent.deltaY < 0) {
$(this).slick('slickPrev');
} else {
$(this).slick('slickNext');
}
}));
.slide {
background: green;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="56253a3f353d7b353724392325333a1667786e7867">[email protected]</a>/slick/slick.css" />
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95e6f9fcf6feb8f6f4e7fae0e6f0f9d5a4bbadbba4">[email protected]</a>/slick/slick.min.js"></script>
<section id="carousel">
<div class=" position-relative">
<div class="container">
<div class="slider">
<div class="slide">
<h1>Slide 1</h1>
</div>
<div class="slide">
<h1>Slide 2</h1>
</div>
<div class="slide">
<h1>Slide 3</h1>
</div>
<div class="slide">
<h1>Slide 4</h1>
</div>
</div>
</div>
</div>
</section>
Any suggestions on how to implement this? To pause page scrolling while carousel is active?