現在很多前端工程師會被要求寫滑動,swiper就是這樣一款滑動特效插件,面向手機、平板、電腦等移動終端。但是在寫頁面時難免會使用多個swiper插件,在我們最近的項目里愛加海外月子中心就出現了這個情況,那么應該如何使用呢?
![]()
swiper是通過共用的class(swiper-container)來實現效果,所以在共用的class前面加上 父元素(你可以定義一個class或id,如此次的.banner、#case)來區分。
var mySwiper = new Swiper('.banner .swiper-container',{
loop: true,
autoplay:3000,
autoplayDisableOnInteraction: false,
speed:500,
// 如果需要分頁器
pagination: '.banner .swiper-pagination',
paginationClickable: true,
grabCursor : true,
nextButton: '.arrow-right',
prevButton: '.arrow-left',
parallax:true,var mySwiper = new Swiper('#case .swiper-container',{
loop: true,
autoplay:3000,
autoplayDisableOnInteraction: false,
speed:500,
// 如果需要分頁器
pagination: '#case .swiper-pagination',
paginationClickable: true,
grabCursor : true,
nextButton: '.arrow-right',
prevButton: '.arrow-left',
parallax:true,
});![]()
![]()
重點就在于這個類,如果一個頁面使用多個swiper插件時,要把各自的父級類名加上才能不沖突。改完 var,記得修改下 pagination 值,其他黑色字體部分,根據你的需求設置即可。
上一篇: css3鼠標劃過如何出現陰影
下一篇: 背景圖如何過渡加載
關鍵詞:



