本文实例为大家分享了vue swiper实现侧滑菜单效果的具体代码,供大家参考,具体内容如下
先上效果图:
这个左右滑动以及上下滑动主要使用了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); }, /*获取随机颜色*/ 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>
该组件自定义了四个属性,分别是左右侧滑菜单的宽度,上下滑动菜单的高度,leftWdith、rightWidth、topHeight、bottomHeight,然后用了一个横向的轮播用来存放左滑菜单,中间内容,右滑菜单,然后在中间内容又放了一个纵向的轮播用来放置上滑菜单,内容以及下滑菜单,具体思路就是这样。在组件挂载的时候,需要根据父组件传入的数值去初始化四个菜单的宽高,初始化完毕宽高之后,还要调用swiper本身的updateSlides更新所有的slides,不然滑动的时候,还是按照没设置之前的宽高进行滑动。在父组件中调用:
<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>
不要忘了在父组件中还要引入这个vue组件。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持小牛知识库。
本文向大家介绍Android中DrawerLayout实现侧滑菜单效果,包括了Android中DrawerLayout实现侧滑菜单效果的使用技巧和注意事项,需要的朋友参考一下 众所周知,android里面我们很熟悉的一个功能,侧滑菜单效果在以前我们大部分都是用的slidingmenu这个开源框架,自从谷歌官方新出的一个DrawerLayout控件之后,越来越多的应用开始使用谷歌的官方的控件写这个效
本文向大家介绍Android_UI 仿QQ侧滑菜单效果的实现,包括了Android_UI 仿QQ侧滑菜单效果的实现的使用技巧和注意事项,需要的朋友参考一下 相信大家对QQ侧滑菜单的效果已经不陌生了吧,侧滑进入个人头像一侧,进行对头像的更改,我的收藏,QQ钱包,我的文件等一系列的操作,今天呢,主要是实现进入侧滑菜单的这一效果原理进行分析. 主要思路分析 1.首先写一个SlideMenu 继承一个
本文向大家介绍Android实现侧滑菜单DrawerLayout,包括了Android实现侧滑菜单DrawerLayout的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了Android实现侧滑菜单的具体代码,供大家参考,具体内容如下 点击左侧滑动 效果如下 代码实现过程: 1.导入框架build.gradle中 2.xml文件 主要的界面放在DrawerLayout 中,需要强调的是
本文向大家介绍Vue侧滑菜单组件——DrawerLayout,包括了Vue侧滑菜单组件——DrawerLayout的使用技巧和注意事项,需要的朋友参考一下 本文介绍一个简单的DrawerLayout(类似Android的DrawerLayout)布局组件的实现,基于Vue.js。介绍的内容已经制作成 vue-drawer-layout 组件。 前言 大家有兴趣先用手机扫一扫这个二维码,或者点我 然
本文向大家介绍Android自定义控件简单实现侧滑菜单效果,包括了Android自定义控件简单实现侧滑菜单效果的使用技巧和注意事项,需要的朋友参考一下 侧滑菜单在很多应用中都会见到,最近QQ5.0侧滑还玩了点花样~~对于侧滑菜单,一般大家都会自定义ViewGroup,然后隐藏菜单栏,当手指滑动时,通过Scroller或者不断的改变leftMargin等实现;多少都有点复杂,完成以后还需要对滑动冲突
本文向大家介绍Android实现3种侧滑效果(仿qq侧滑、抽屉侧滑、普通侧滑),包括了Android实现3种侧滑效果(仿qq侧滑、抽屉侧滑、普通侧滑)的使用技巧和注意事项,需要的朋友参考一下 自己实现了一下侧滑的三种方式(注释都写代码里了) 本文Demo下载地址:Andriod侧滑 本文实现所需框架:nineoldandroids下载地址:nineoldandroids 1.普通侧滑: 主要是基于
本文向大家介绍Android利用滑动菜单框架实现滑动菜单效果,包括了Android利用滑动菜单框架实现滑动菜单效果的使用技巧和注意事项,需要的朋友参考一下 之前我向大家介绍了史上最简单的滑动菜单的实现方式,相信大家都还记得。如果忘记了其中的实现原理或者还没看过的朋友,请先去看一遍之前的文章Android仿人人客户端滑动菜单的侧滑特效实现代码,史上最简单的侧滑实现 ,因为我们今天要实现的滑动菜单框架
本文向大家介绍Vue实现侧边菜单栏手风琴效果实例代码,包括了Vue实现侧边菜单栏手风琴效果实例代码的使用技巧和注意事项,需要的朋友参考一下 效果图如下所示: 总结 以上所述是小编给大家介绍的Vue实现侧边菜单栏手风琴效果实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对呐喊教程网站的支持!