欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue中使用swiper,左右箭頭點(diǎn)擊沒有效果問題及解決

 更新時(shí)間:2023年05月18日 08:52:00   作者:沙門空海  
這篇文章主要介紹了vue中使用swiper,左右箭頭點(diǎn)擊沒有效果問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

vue使用swiper,左右箭頭點(diǎn)擊沒有效果

swiper作為一個(gè)開源的前端組件,主要用來做各種頁面切換輪播的效果。

在做左右切換效果時(shí),發(fā)現(xiàn)點(diǎn)擊左右箭頭沒有效果,原來是需要在左右箭頭的頁面標(biāo)簽上添加點(diǎn)擊事件才行。

代碼如下,親測可用

<swiper ref="mySwiper" :options="swiperOptions">
                <swiper-slide><div style="background-color: #5cb85c;height: 100%"><img src="../assets/logo.png" style="height: 100%;width: 100%"></div></swiper-slide>
                <swiper-slide><div style="background-color: #5cb85c;height: 100%"><img src="../assets/logo.png" style="height: 100%;width: 100%"></div></swiper-slide>
                <swiper-slide><div style="background-color: #5cb85c;height: 100%"><img src="../assets/logo.png" style="height: 100%;width: 100%"></div></swiper-slide>
                <swiper-slide><div style="background-color: #5cb85c;height: 100%"><img src="../assets/logo.png" style="height: 100%;width: 100%"></div></swiper-slide>
                <swiper-slide><div style="background-color: #5cb85c;height: 100%"><img src="../assets/logo.png" style="height: 100%;width: 100%"></div></swiper-slide>
                <swiper-slide><div style="background-color: #5cb85c;height: 100%"><img src="../assets/logo.png" style="height: 100%;width: 100%"></div></swiper-slide>
                <!-- Add Pagination -->
                <div class="swiper-pagination" slot="pagination"></div>
              </swiper>
              <!-- Add Arrows -->
              <div class="swiper-button-next" slot="button-next" @click="next"></div>
              <div class="swiper-button-prev" slot="button-prev" @click="prev"></div>
data(){
      return{
        swiperOptions: {
          slidesPerView: 3,
          slidesPerGroup: 3,
          loopFillGroupWithBlank: true,
          pagination: {
            el: '.swiper-pagination',
            clickable: true,
          },
          navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
          },
        },
      }
    },
computed:{
      swiper() {
        return this.$refs.mySwiper.$swiper
      }
    },
methods:{
      prev(){
        this.swiper.slidePrev();
      },
      next(){
        this.swiper.slideNext();
      },
}

swiper插件自定義切換箭頭按鈕

不知道大家在使用swiper時(shí)有沒有遇到這樣一種需求,話不多說,直接上gif。

這里寫圖片描述

也就是需要把左右切換的箭頭移到容器的外面,自定義箭頭的樣式。

給swiper容器再加一個(gè)父容器,兩個(gè)容器之間留下間隙,箭頭定位到間隙之間就ok了。

箭頭默認(rèn)是絕對定位的,給父容器一個(gè)相對定位,就能夠調(diào)整箭頭位置。此外箭頭用的是背景圖,改變箭頭大小的同時(shí)記得改變背景圖大小。

上代碼。

<style>
        .out_container{
            width: 280px;
            height: 150px;
            margin: 100px auto;
            position: relative;
            outline: 1px solid black;
        }
        .in_container{
            width: 216px;
            height: 130px;
            margin: 0 auto;
            overflow: hidden;
        }
        .swiper_btn{
            width: 20px;
            height: 20px;
            background-size: contain;
        }
    </style>
<body>
    <div class="out_container">
        <div class="in_container">
            <div class="swiper-wrapper">
                <div class="swiper-slide"><img src="" alt=""></div>
                <div class="swiper-slide"><img src="" alt=""></div>
                <div class="swiper-slide"><img src="" alt=""></div>
            </div>
            <div class="swiper-button-prev swiper_btn"></div>
            <div class="swiper-button-next swiper_btn"></div>
        </div>
    </div>
</body>
<script>
    var mySwiper = new Swiper('.in_container', {
        prevButton: '.swiper-button-prev',
        nextButton: '.swiper-button-next',
    })
</script>

效果如下

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。 

相關(guān)文章

  • vue 判斷兩個(gè)時(shí)間插件結(jié)束時(shí)間必選大于開始時(shí)間的代碼

    vue 判斷兩個(gè)時(shí)間插件結(jié)束時(shí)間必選大于開始時(shí)間的代碼

    這篇文章主要介紹了vue 判斷兩個(gè)時(shí)間插件結(jié)束時(shí)間必選大于開始時(shí)間的代碼,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • 詳解vue3.x頁面功能拆分方式

    詳解vue3.x頁面功能拆分方式

    本文主要介紹了vue3.x頁面功能拆分方式,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • VUE前后端學(xué)習(xí)tab寫法實(shí)例

    VUE前后端學(xué)習(xí)tab寫法實(shí)例

    在本篇文章里小編給大家分享了關(guān)于VUE前后端學(xué)習(xí)tab寫法實(shí)例以及相關(guān)知識點(diǎn),需要的朋友們參考下。
    2019-08-08
  • vue使用rem實(shí)現(xiàn) 移動(dòng)端屏幕適配

    vue使用rem實(shí)現(xiàn) 移動(dòng)端屏幕適配

    這篇文章主要介紹了vue使用rem實(shí)現(xiàn) 移動(dòng)端屏幕適配的相關(guān)知識,通過實(shí)例代碼介紹了vue用rem布局的實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2018-09-09
  • vue-router傳遞參數(shù)的幾種方式實(shí)例詳解

    vue-router傳遞參數(shù)的幾種方式實(shí)例詳解

    vue-router傳遞參數(shù)分為兩大類,一類是編程式的導(dǎo)航 router.push另一類是聲明式的導(dǎo)航 <router-link>,本文通過實(shí)例代碼給大家介紹vue-router傳遞參數(shù)的幾種方式,感興趣的朋友跟隨小編一起看看吧
    2018-11-11
  • 使用Vue自定義數(shù)字鍵盤組件(體驗(yàn)度極好)

    使用Vue自定義數(shù)字鍵盤組件(體驗(yàn)度極好)

    最近做 Vue 開發(fā),因?yàn)橛胁簧夙撁嫔婕暗浇痤~輸入,產(chǎn)品老是覺得用原生的 input 進(jìn)行金額輸入的話 體驗(yàn)很不好,于是自己動(dòng)手寫了一個(gè)使用Vue自定義數(shù)字鍵盤組件,具體實(shí)現(xiàn)代碼大家參考下本文
    2017-12-12
  • elementui源碼學(xué)習(xí)仿寫一個(gè)el-tooltip示例

    elementui源碼學(xué)習(xí)仿寫一個(gè)el-tooltip示例

    本篇文章記錄仿寫一個(gè)el-tooltip組件細(xì)節(jié),從而有助于大家更好理解餓了么ui對應(yīng)組件具體工作細(xì)節(jié),本文是elementui源碼學(xué)習(xí)仿寫系列的又一篇文章,后續(xù)空閑了會不斷更新并仿寫其他組件
    2023-07-07
  • Vue3之路由的元數(shù)據(jù)信息meta詳解

    Vue3之路由的元數(shù)據(jù)信息meta詳解

    這篇文章主要介紹了Vue3之路由的元數(shù)據(jù)信息meta詳解,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • 對vue中的input輸入框進(jìn)行郵箱驗(yàn)證方式

    對vue中的input輸入框進(jìn)行郵箱驗(yàn)證方式

    這篇文章主要介紹了對vue中的input輸入框進(jìn)行郵箱驗(yàn)證方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • vue使用JSEncrypt對密碼本地存儲時(shí)加解密的實(shí)現(xiàn)

    vue使用JSEncrypt對密碼本地存儲時(shí)加解密的實(shí)現(xiàn)

    本文主要介紹了vue使用JSEncrypt對密碼本地存儲時(shí)加解密,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07

最新評論