vue3.x使用swiper實(shí)現(xiàn)卡片輪播
本文實(shí)例為大家分享了vue3.x使用swiper實(shí)現(xiàn)卡片輪播的具體代碼,供大家參考,具體內(nèi)容如下
版本號(hào):
vue/cli:4.5.12
swiper:^6.8.4
安裝
npm install --save swiper
使用以及配置
<div class="swiper-container home_swiper">
?? ?<div class="swiper-wrapper">
?? ??? ?<div class="swiper-slide" v-for="(item,index) in aImages" :key="index">
?? ??? ??? ?<img :src="item.picUrl" alt="" />
?? ??? ?</div>
?? ?</div>
</div>
import {
?? ?ref,
?? ?nextTick
} from 'vue';
import Swiper, {
?? ?Autoplay,
?? ?EffectCoverflow
} from "swiper";
Swiper.use([Autoplay, EffectCoverflow]);
import "swiper/swiper.scss";
export default {
?? ?setup() {
?? ??? ?const aImages = ref([]);
?? ??? ?const fInitSwiper = () => {
?? ??? ??? ?new Swiper(".home_swiper", {
?? ??? ??? ??? ?//循環(huán)
?? ??? ??? ??? ?loop: true,
?? ??? ??? ??? ?//每張播放時(shí)長3秒,自動(dòng)播放
?? ??? ??? ??? ?spaceBetween: 16,
?? ??? ??? ??? ?// 切換效果?
?? ??? ??? ??? ?effect: "coverflow",
?? ??? ??? ??? ?// 該選項(xiàng)給Swiper用戶提供小小的貼心應(yīng)用,設(shè)置為true時(shí),鼠標(biāo)覆蓋Swiper時(shí)指針會(huì)變成手掌形狀,拖動(dòng)時(shí)指針會(huì)變成抓手形狀。
?? ??? ??? ??? ?grabCursor: true,
?? ??? ??? ??? ?// 設(shè)定為true時(shí),active slide會(huì)居中,而不是默認(rèn)狀態(tài)下的居左。
?? ??? ??? ??? ?centeredSlides: true,
?? ??? ??? ??? ?// 設(shè)置slider容器能夠同時(shí)顯示的slides數(shù)量(carousel模式)。
?? ??? ??? ??? ?slidesPerView: 1.32,
?? ??? ??? ??? ?// 啟動(dòng)動(dòng)態(tài)檢查器(OB/觀眾/觀看者),當(dāng)改變swiper的樣式(例如隱藏/顯示)或者修改swiper的子元素時(shí),自動(dòng)初始化swiper。默認(rèn)false,不開啟,可以使用update()方法更新。
?? ??? ??? ??? ?observer: true,
?? ??? ??? ??? ?observeParents: true,
?? ??? ??? ??? ?observeSlideChildren: true,
?? ??? ??? ??? ?// 自動(dòng)切換
?? ??? ??? ??? ?autoplay: {
?? ??? ??? ??? ??? ?// 自動(dòng)切換的時(shí)間間隔
?? ??? ??? ??? ??? ?delay: 3000,
?? ??? ??? ??? ??? ?// 如果設(shè)置為true,當(dāng)切換到最后一個(gè)slide時(shí)停止自動(dòng)切換
?? ??? ??? ??? ??? ?stopOnLastSlide: false,
?? ??? ??? ??? ??? ?// 用戶操作swiper之后,是否禁止autoplay。默認(rèn)為true:停止
?? ??? ??? ??? ??? ?disableOnInteraction: false,
?? ??? ??? ??? ?},
?? ??? ??? ??? ?// 類似于蘋果將多首歌曲的封面以3D界面的形式顯示出來的方式
?? ??? ??? ??? ?coverflowEffect: {
?? ??? ??? ??? ??? ?// slide做3d旋轉(zhuǎn)時(shí)Y軸的旋轉(zhuǎn)角度
?? ??? ??? ??? ??? ?rotate: 0,
?? ??? ??? ??? ??? ?// 每個(gè)slide之間的拉伸值,越大slide靠得越緊。5.3.6 后可使用%百分比
?? ??? ??? ??? ??? ?stretch: -70,
?? ??? ??? ??? ??? ?// slide的位置深度。值越大z軸距離越遠(yuǎn),看起來越小。
?? ??? ??? ??? ??? ?depth: 500,
?? ??? ??? ??? ??? ?// depth和rotate和stretch的倍率,相當(dāng)于depth*modifier、rotate*modifier、stretch*modifier,值越大這三個(gè)參數(shù)的效果越明顯。
?? ??? ??? ??? ??? ?modifier: 1,
?? ??? ??? ??? ??? ?// 是否開啟slide陰影
?? ??? ??? ??? ??? ?slideShadows: true,
?? ??? ??? ??? ?},
?? ??? ??? ?});
?? ??? ?};
?? ??? ?return {
?? ??? ??? ?aImages?
?? ??? ?}
?? ?}
}展示效果

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue+高德地圖實(shí)現(xiàn)地圖搜索及點(diǎn)擊定位操作
這篇文章主要介紹了vue+高德地圖實(shí)現(xiàn)地圖搜索及點(diǎn)擊定位操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09
vue3.0+echarts實(shí)現(xiàn)立體柱圖
這篇文章主要為大家詳細(xì)介紹了vue3.0+echarts實(shí)現(xiàn)立體柱圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
Nuxt.js SSR與權(quán)限驗(yàn)證的實(shí)現(xiàn)
這篇文章主要介紹了Nuxt.js SSR與權(quán)限驗(yàn)證的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11
vue2.x 通過后端接口代理,獲取qq音樂api的數(shù)據(jù)示例
今天小編就為大家分享一篇vue2.x 通過后端接口代理,獲取qq音樂api的數(shù)據(jù)示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10
vue2.x中keep-alive源碼解析(實(shí)例代碼)
Keep-Alive模式避免頻繁創(chuàng)建、銷毀鏈接,允許多個(gè)請(qǐng)求和響應(yīng)使用同一個(gè)HTTP鏈接,這篇文章主要介紹了vue2.x中keep-alive源碼解析,需要的朋友可以參考下2023-02-02
daisyUI解決TailwindCSS堆砌class問題詳解
這篇文章主要為大家介紹了daisyUI解決TailwindCSS堆砌class問題詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
el-form-item表單label添加提示圖標(biāo)的實(shí)現(xiàn)
本文主要介紹了el-form-item表單label添加提示圖標(biāo)的實(shí)現(xiàn),我們將了解El-Form-Item的基本概念和用法,及添加提示圖標(biāo)以及如何自定義圖標(biāo)樣式,感興趣的可以了解一下2023-11-11
Vite處理html模板插件之vite-plugin-html插件使用
這篇文章主要給大家介紹了關(guān)于Vite處理html模板插件之vite-plugin-html插件使用的相關(guān)資料,Vite是一個(gè)現(xiàn)代化的前端構(gòu)建工具,而vite-plugin-html是Vite的一個(gè)插件,用于在構(gòu)建時(shí)自動(dòng)生成HTML文件,需要的朋友可以參考下2023-10-10

