SwiperJS - 上一个和下一个按钮不起作用
SwiperJS - Previous and Next buttons not working
我正在使用 SwiperJS (www.swiperjs.com),我遇到了一个问题,滑动到下一张照片可以正常工作,但上一个和下一个按钮不起作用。我已经查看了在这里可以找到的每篇文章并遵循了他们的文档,但仍然没有任何运气。
<div id="openModal" class="modalDialog" style="display: none;">
<div class="modal-content">
<a href="#close" title="Close" class="close" onclick="$('#openModal').hide()">X</a>
<h2>Modal Box</h2>
<p>Hello world</p>
<script src="https://unpkg.com/swiper/js/swiper.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.css">
<link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.min.css">
<!-- Slider main container -->
<div class="swiper-container">
<!-- Additional required wrapper -->
<div id="swiper" class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide"><img src="http://<server>/path/to/image.png"></div>
<div class="swiper-slide"><img src="http://<server>/path/to/image2.png"></div>
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
</div>
<script>
var mySwiper = new Swiper ('.swiper-container', {
// Optional parameters
direction: 'horizontal',
loop: true,
centeredSlides: true,
slidesPerView: 1,
pagination: '.swiper-pagination',
paginationClickable: '.swiper-pagination',
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
})
</script>
为了初始化 Swiper JS,我也在他们的网站上进行了尝试:
<script>
var mySwiper = new Swiper ('.swiper-container', {
// Optional parameters
direction: 'vertical',
loop: true,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// And if we need scrollbar
scrollbar: {
el: '.swiper-scrollbar',
},
})
</script>
有人知道我可以尝试什么吗?我还发现分页按钮没有像示例中那样显示在底部,但与上一个和下一个按钮不起作用相比,这不是一个问题。就像我说的,如果我单击并拖动或 "swipe," 它会很好地移动到下一张幻灯片,所以我假设它与 JS 部分相关,但不确定要尝试什么。
在您发布的代码的第一部分中,将您必须的 JS 更改为
<script>
var mySwiper = new Swiper ('.swiper-container', {
// Optional parameters
direction: 'horizontal',
loop: true,
centeredSlides: true,
slidesPerView: 1,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
})
</script>
箭头和分页都应该有效。
我改的是
pagination: '.swiper-pagination',
paginationClickable: '.swiper-pagination',
到
pagination: {
el: '.swiper-pagination',
clickable: true,
},
和
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
到
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
感谢您的帮助!我的问题最终是我需要将其添加到我的滑动器配置中:
observer: true,
observeParents: true,
parallax:true,
这是因为滑动条位于隐藏的模态框内。
只是我们需要在swiper js配置下面添加
observer: true,
observeParents: true,
parallax:true,
所以这是完整的配置
var swiper = new Swiper('.relatedproducts', {
observer: true,
observeParents: true,
parallax:true,
slidesPerView: 6,
loop:true,
autoplay: true,
simulateTouch:true,
navigation: {
nextEl: '.relatedproducts .swiper-button-next',
prevEl: '.relatedproducts .swiper-button-prev',
},
});
这对我有用
按此方式连接滑块,一切正常!
import { Swiper, Parallax, Navigation} from 'swiper'
Swiper.use([ Parallax, Navigation ])
document.addEventListener('DOMContentLoaded', () => {
const swiper = new Swiper('.swiper-container', {
// Optional parameters
direction: 'horizontal',
loop: false,
speed: 2400,
parallax: true,
loop: false,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
});
})
我正在使用 SwiperJS (www.swiperjs.com),我遇到了一个问题,滑动到下一张照片可以正常工作,但上一个和下一个按钮不起作用。我已经查看了在这里可以找到的每篇文章并遵循了他们的文档,但仍然没有任何运气。
<div id="openModal" class="modalDialog" style="display: none;">
<div class="modal-content">
<a href="#close" title="Close" class="close" onclick="$('#openModal').hide()">X</a>
<h2>Modal Box</h2>
<p>Hello world</p>
<script src="https://unpkg.com/swiper/js/swiper.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.css">
<link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.min.css">
<!-- Slider main container -->
<div class="swiper-container">
<!-- Additional required wrapper -->
<div id="swiper" class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide"><img src="http://<server>/path/to/image.png"></div>
<div class="swiper-slide"><img src="http://<server>/path/to/image2.png"></div>
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
</div>
<script>
var mySwiper = new Swiper ('.swiper-container', {
// Optional parameters
direction: 'horizontal',
loop: true,
centeredSlides: true,
slidesPerView: 1,
pagination: '.swiper-pagination',
paginationClickable: '.swiper-pagination',
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
})
</script>
为了初始化 Swiper JS,我也在他们的网站上进行了尝试:
<script>
var mySwiper = new Swiper ('.swiper-container', {
// Optional parameters
direction: 'vertical',
loop: true,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// And if we need scrollbar
scrollbar: {
el: '.swiper-scrollbar',
},
})
</script>
有人知道我可以尝试什么吗?我还发现分页按钮没有像示例中那样显示在底部,但与上一个和下一个按钮不起作用相比,这不是一个问题。就像我说的,如果我单击并拖动或 "swipe," 它会很好地移动到下一张幻灯片,所以我假设它与 JS 部分相关,但不确定要尝试什么。
在您发布的代码的第一部分中,将您必须的 JS 更改为
<script>
var mySwiper = new Swiper ('.swiper-container', {
// Optional parameters
direction: 'horizontal',
loop: true,
centeredSlides: true,
slidesPerView: 1,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
})
</script>
箭头和分页都应该有效。
我改的是
pagination: '.swiper-pagination',
paginationClickable: '.swiper-pagination',
到
pagination: {
el: '.swiper-pagination',
clickable: true,
},
和
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
到
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
感谢您的帮助!我的问题最终是我需要将其添加到我的滑动器配置中:
observer: true,
observeParents: true,
parallax:true,
这是因为滑动条位于隐藏的模态框内。
只是我们需要在swiper js配置下面添加
observer: true,
observeParents: true,
parallax:true,
所以这是完整的配置
var swiper = new Swiper('.relatedproducts', {
observer: true,
observeParents: true,
parallax:true,
slidesPerView: 6,
loop:true,
autoplay: true,
simulateTouch:true,
navigation: {
nextEl: '.relatedproducts .swiper-button-next',
prevEl: '.relatedproducts .swiper-button-prev',
},
});
这对我有用
按此方式连接滑块,一切正常!
import { Swiper, Parallax, Navigation} from 'swiper'
Swiper.use([ Parallax, Navigation ])
document.addEventListener('DOMContentLoaded', () => {
const swiper = new Swiper('.swiper-container', {
// Optional parameters
direction: 'horizontal',
loop: false,
speed: 2400,
parallax: true,
loop: false,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
});
})