最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

在做左右切換效果時,發(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時有沒有遇到這樣一種需求,話不多說,直接上gif。

這里寫圖片描述

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

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

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

上代碼。

<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é)

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

相關(guān)文章

最新評論

遂宁市| 静宁县| 娱乐| 诸城市| 日喀则市| 车致| 探索| 阳泉市| 辛集市| 乌什县| 小金县| 博白县| 遂川县| 二连浩特市| 始兴县| 平湖市| 称多县| 思南县| 天长市| 波密县| 宿迁市| 丁青县| 勃利县| 贵阳市| 翼城县| 内江市| 安福县| 遵义市| 开化县| 平罗县| 炎陵县| 武山县| 漯河市| 娱乐| 葫芦岛市| 集安市| 鄄城县| 临汾市| 怀宁县| 保靖县| 拉孜县|