vue+swiper实现侧滑菜单效果


Posted in Javascript onDecember 28, 2017

本文实例为大家分享了vue swiper实现侧滑菜单效果的具体代码,供大家参考,具体内容如下

先上效果图:

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组件。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
datagrid框架的删除添加与修改
Apr 08 Javascript
查找页面中所有类为test的结点的方法
Mar 28 Javascript
使用js画图之圆、弧、扇形
Jan 12 Javascript
通过node-mysql搭建Windows+Node.js+MySQL环境的教程
Mar 01 Javascript
JavaScript作用域示例详解
Jul 07 Javascript
详解jquery easyui之datagrid使用参考
Dec 05 Javascript
Bootstrap的popover(弹出框)2秒后定时消失的实现代码
Feb 27 Javascript
vue+springboot前后端分离实现单点登录跨域问题解决方法
Jan 30 Javascript
vue项目中添加单元测试的方法
Jul 21 Javascript
说说Vuex的getters属性的具体用法
Apr 15 Javascript
vue学习之Vue-Router用法实例分析
Jan 06 Javascript
JavaScript如何操作css
Oct 24 Javascript
swiper插件自定义切换箭头按钮
Dec 28 #Javascript
swiper移动端轮播插件(触碰图片之后停止轮播)
Dec 28 #Javascript
Vue组件通信之Bus的具体使用
Dec 28 #Javascript
基于Swiper实现移动端页面图片轮播效果
Dec 28 #Javascript
Swiper自定义分页器使用详解
Dec 28 #Javascript
swiper自定义分页器使用方法详解
Sep 14 #Javascript
JavaScript实现数值自动增加动画
Dec 28 #Javascript
You might like
基于swoole实现多人聊天室
2018/06/14 PHP
DOMAssitant最新版 DOMAssistant 2.5发布
2007/12/25 Javascript
json跟xml的对比分析
2008/06/10 Javascript
JavaScript 判断浏览器类型及版本
2009/02/21 Javascript
Javascript isArray 数组类型检测函数
2009/10/08 Javascript
JQuery Study Notes 学习笔记(一)
2010/08/04 Javascript
使用原生js封装webapp滑动效果(惯性滑动、滑动回弹)
2014/05/06 Javascript
JavaScript实现Java中StringBuffer的方法
2015/02/09 Javascript
在AngularJS中使用AJAX的方法
2015/06/17 Javascript
jQuery 监控键盘一段时间没输入
2016/04/22 Javascript
Vue使用json-server进行后端数据模拟功能
2018/04/17 Javascript
vue中v-text / v-html使用实例代码详解
2019/04/02 Javascript
JS实现给数组对象排序的方法分析
2019/06/24 Javascript
js设计模式之代理模式及订阅发布模式实例详解
2019/08/15 Javascript
浅谈Vue使用Cascader级联选择器数据回显中的坑
2020/10/31 Javascript
[51:52]Liquid vs Secret 2019国际邀请赛淘汰赛 败者组 BO3 第二场 8.24
2019/09/10 DOTA
[27:08]完美世界DOTA2联赛PWL S2 SZ vs Rebirth 第二场 11.21
2020/11/23 DOTA
python寻找list中最大值、最小值并返回其所在位置的方法
2018/06/27 Python
Python实现定期检查源目录与备份目录的差异并进行备份功能示例
2019/02/27 Python
使用Python做定时任务及时了解互联网动态
2019/05/15 Python
Django打印出在数据库中执行的语句问题
2019/07/25 Python
Python TCPServer 多线程多客户端通信的实现
2019/12/31 Python
python实现每天自动签到领积分的示例代码
2020/08/18 Python
webapp字号大小跟随系统字号大小缩放的示例代码
2018/12/26 HTML / CSS
免税水晶:Duty Free Crystal
2019/05/13 全球购物
Marlies Dekkers内衣荷兰官方网店:荷兰奢侈内衣品牌
2020/03/27 全球购物
const char*, char const*, char*const的区别是什么
2014/07/09 面试题
企业精神口号
2014/06/11 职场文书
高中综合实践活动总结
2014/07/07 职场文书
校园新闻广播稿5篇
2014/10/10 职场文书
慰问信格式
2015/02/14 职场文书
财务稽核岗位职责
2015/04/13 职场文书
导游词之吉林花园山
2019/10/17 职场文书
对Golang中的FORM相关字段理解
2021/05/02 Golang
MySQL 覆盖索引的优点
2021/05/19 MySQL
详解CSS中postion和opacity及cursor的特性
2022/08/14 HTML / CSS