vue+swiper實(shí)現(xiàn)側(cè)滑菜單效果
本文實(shí)例為大家分享了vue swiper實(shí)現(xiàn)側(cè)滑菜單效果的具體代碼,供大家參考,具體內(nèi)容如下
先上效果圖:
這個(gè)左右滑動(dòng)以及上下滑動(dòng)主要使用了Swiper的輪播功能,首先是該自定義組件的代碼:
<template> <div class="s-slider"> <swiper :options="horizontalSwiperOptions" ref="horizontalSwiper"> <swiper-slide class="left" ref="left" v-bind:style="{'background':getRandomColor()}"> <slot name="left"></slot> </swiper-slide> <swiper-slide class="content"> <swiper :options="verticalSwiperOptions" ref="verticalSwiper"> <swiper-slide class="top" ref="top" v-bind:style="{'background':getRandomColor()}"> <slot name="top"></slot> </swiper-slide> <swiper-slide class="content" ref="content" v-bind:style="{'background':getRandomColor()}"> <slot name="content"></slot> </swiper-slide> <swiper-slide class="bottom" ref="bottom" v-bind:style="{'background':getRandomColor()}"> <slot name="bottom"></slot> </swiper-slide> </swiper> </swiper-slide> <swiper-slide class="right" ref="right" v-bind:style="{'background':getRandomColor()}"> <slot name="right"></slot> </swiper-slide> </swiper> </div> </template> <script> import {swiper, swiperSlide, swiperWraper} from 'vue-awesome-swiper' export default { name: "s-slider", props: ['leftWidth','rightWidth','topHeight','bottomHeight'], data() { return { horizontalSwiperOptions: { slidesPerView: 'auto', initialSlide: 0, direction: 'horizontal' }, verticalSwiperOptions:{ slidesPerView: 'auto', initialSlide: 0, direction: 'vertical' } } }, mounted() { setTimeout(() => { this._initMenuWidth(); }, 20); }, methods: { _initMenuWidth() { this.$refs.left.$el.style.width = this.leftWidth; this.$refs.right.$el.style.width = this.rightWidth; this.$refs.top.$el.style.height = this.topHeight; this.$refs.bottom.$el.style.height = this.bottomHeight; this.horizontalSwiper.updateSlides(); this.horizontalSwiper.slideTo(1, 1000, false); this.verticalSwiper.updateSlides(); this.verticalSwiper.slideTo(1, 1000, false); }, /*獲取隨機(jī)顏色*/ getRandomColor() { return "#" + ("00000" + ((Math.random() * 16777215 + 0.5) >> 0).toString(16)).slice(-6); } }, computed: { horizontalSwiper() { return this.$refs.horizontalSwiper.swiper; }, verticalSwiper(){ return this.$refs.verticalSwiper.swiper; } } } </script> <style scoped lang="scss"> @import "src/base/css/public/variable.scss"; @import "swiper/dist/css/swiper.css"; .s-slider { height: 100%; color: white; .swiper-container { @include fill-with-parent } } </style>
該組件自定義了四個(gè)屬性,分別是左右側(cè)滑菜單的寬度,上下滑動(dòng)菜單的高度,leftWdith、rightWidth、topHeight、bottomHeight,然后用了一個(gè)橫向的輪播用來(lái)存放左滑菜單,中間內(nèi)容,右滑菜單,然后在中間內(nèi)容又放了一個(gè)縱向的輪播用來(lái)放置上滑菜單,內(nèi)容以及下滑菜單,具體思路就是這樣。在組件掛載的時(shí)候,需要根據(jù)父組件傳入的數(shù)值去初始化四個(gè)菜單的寬高,初始化完畢寬高之后,還要調(diào)用swiper本身的updateSlides更新所有的slides,不然滑動(dòng)的時(shí)候,還是按照沒(méi)設(shè)置之前的寬高進(jìn)行滑動(dòng)。在父組件中調(diào)用:
<s-slider leftWidth="200px" rightWidth="300px" topHeight="100px" bottomHeight="150px"> <div slot="left"> left </div> <div slot="content"> Content </div> <div slot="right"> right </div> <div slot="top"> top </div> <div slot="bottom"> bottom </div> </s-slider>
不要忘了在父組件中還要引入這個(gè)vue組件。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue2中引用及使用 better-scroll的方法詳解
- 詳解 vue better-scroll滾動(dòng)插件排坑
- vue2.0 better-scroll 實(shí)現(xiàn)移動(dòng)端滑動(dòng)的示例代碼
- vue使用 better-scroll的參數(shù)和方法詳解
- vue利用better-scroll實(shí)現(xiàn)輪播圖與頁(yè)面滾動(dòng)詳解
- vue滾動(dòng)軸插件better-scroll使用詳解
- vue 下列表側(cè)滑操作實(shí)例代碼詳解
- Vue側(cè)滑菜單組件——DrawerLayout
- vue中使用better-scroll實(shí)現(xiàn)滑動(dòng)效果及注意事項(xiàng)
相關(guān)文章
Vue組件傳值方式(props屬性,父到子,子到父,兄弟傳值)
這篇文章主要介紹了Vue組件傳值方式(props屬性,父到子,子到父,兄弟傳值),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06Vue中computed、methods與watch的區(qū)別總結(jié)
這篇文章主要給大家介紹了關(guān)于Vue中computed、methods與watch區(qū)別的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04基于vue.js實(shí)現(xiàn)購(gòu)物車(chē)
這篇文章主要為大家詳細(xì)介紹了基于vue.js實(shí)現(xiàn)購(gòu)物車(chē),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-01-01vue使用element-ui的el-image的問(wèn)題分析
這篇文章主要介紹了vue使用element-ui的el-image的問(wèn)題分析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01vue實(shí)現(xiàn)在表格里,取每行的id的方法
下面小編就為大家分享一篇vue實(shí)現(xiàn)在表格里,取每行的id的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-03-03解決mpvue + vuex 開(kāi)發(fā)微信小程序vuex輔助函數(shù)mapState、mapGetters不可用問(wèn)題
這篇文章主要介紹了解決mpvue + vuex 開(kāi)發(fā)微信小程序 vuex輔助函數(shù)mapState、mapGetters不可用問(wèn)題,需要的朋友可以參考下2018-08-08vue富文本框(插入文本、圖片、視頻)的使用及問(wèn)題小結(jié)
這篇文章主要介紹了vue富文本框(插入文本、圖片、視頻)的使用及問(wèn)題小結(jié),需要的朋友可以參考下2018-08-08詳解vue項(xiàng)目打包后通過(guò)百度的BAE發(fā)布到網(wǎng)上的流程
這篇文章主要介紹了將vue的項(xiàng)目打包后通過(guò)百度的BAE發(fā)布到網(wǎng)上的流程,主要運(yùn)用的技術(shù)是vue+express+git+百度的應(yīng)用引擎BAE。需要的朋友可以參考下2018-03-03