光滑的slidesToScroll已经设置为3,所以当我到达第四段时,光滑的导航更改为下一个slidesToScroll,我可以实现这个吗,谢谢。我正在使用交叉点观察器。
如果我可以控制数据幻灯片属性,也许我可以实现这一点。
$(document).ready(function () {
$('.container').slick({
dots: false,
infinite: false,
speed: 300,
slidesToShow:3,
slidesToScroll: 3
});
});
//Intersection observer
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
const id = entry.target.getAttribute('id');
const links = document.querySelectorAll(`#action a[href="#${id}"]`);
if (entry.intersectionRatio > 0) {
links.forEach(link =>{
link.classList.add('active');
});
}
else {
links.forEach(link =>{
link.classList.remove('active');
});
}
});
});
// Track all sections that have an `id` applied
document.querySelectorAll('.table p[id]').forEach((section) => {
observer.observe(section);
});
.active{
color:red
}
//Slick Navigation
<div id="action" class="container">
<a href="#one" data-slide="1">go to slide 1</a>
<a href="#two">go to slide 2</a>
<a href="#three">go to slide 3</a>
<a href="#four" data-slide="4">go to slide 4</a>
<a href="#five">go to slide 5</a>
<a href="#six">go to slide 6</a>
<a href="#seven">go to slide 7</a>
<a href="#eight" data-slide="8">go to slide 8</a>
</div>
<div class="table">
<p id="one" style="margin-bottom: 100%;">Hello</p>
<p id="two" style="margin-bottom: 100%;">Hello 1</p>
<p id="three" style="margin-bottom: 100%;">Hello 2</p>
<p id="four" style="margin-bottom: 100%;">Hello 3</p>
<p id="five" style="margin-bottom: 100%;">Hello 4</p>
<p id="six" style="margin-bottom: 100px;">Hello 5</p>
<p id="seven" style="margin-bottom: 100px;">Hello 6</p>
<p id="eight" style="margin-bottom: 100px;">Hello 7</p>
</div>
1条答案
按热度按时间wgx48brx1#
您可以使用slickGoTo导航所需的幻灯片。
更新代码并在活动幻灯片上添加slickGoTo。