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 相关文章推荐
javascript+xml技术实现分页浏览
Jul 27 Javascript
用js调用迅雷下载代码的二种方法
Apr 15 Javascript
jQuery中add()方法用法实例
Jan 08 Javascript
js常用系统函数用法实例分析
Jan 12 Javascript
JavaScript判断字符长度、数字、Email、电话等常用判断函数分享
Apr 01 Javascript
AngularJS中如何使用$parse或$eval在运行时对Scope变量赋值
Jan 25 Javascript
使用jquery提交form表单并自定义action的方法
May 25 Javascript
Html中 IFrame的用法及注意点
Dec 22 Javascript
angular.fromJson与toJson方法用法示例
May 17 Javascript
微信小程序bindtap事件与冒泡阻止详解
Aug 08 Javascript
vue+高德地图实现地图搜索及点击定位操作
Sep 09 Javascript
js 数组 fill() 填充方法
Nov 02 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
PHP+jQuery实现自动补全功能源码
2013/05/15 PHP
php中并发读写文件冲突的解决方案
2013/10/25 PHP
php共享内存段示例分享
2014/01/20 PHP
php 字符串中的\n换行符无效、不能换行的解决方法
2014/04/02 PHP
在PHP模板引擎smarty生成随机数的方法和math函数详解
2014/04/24 PHP
扩展jquery实现客户端表格的分页、排序功能代码
2011/03/16 Javascript
JS.findElementById()使用介绍
2013/09/21 Javascript
ajax提交表单实现网页无刷新注册示例
2014/05/08 Javascript
jQuery CSS()方法改变现有的CSS样式
2014/08/20 Javascript
JavaScript设计模式之外观模式介绍
2014/12/28 Javascript
详解AngularJS控制器的使用
2016/03/09 Javascript
JS递归遍历对象获得Value值方法技巧
2016/06/14 Javascript
jQuery中的ready函数与window.onload谁先执行
2016/06/21 Javascript
JS实现滑动门效果的方法详解
2016/12/19 Javascript
JS前端开发判断是否是手机端并跳转操作(小结)
2017/02/05 Javascript
Bootstrap modal 多弹窗之叠加引起的滚动条遮罩阴影问题
2017/02/27 Javascript
jQuery日期范围选择器附源码下载
2017/05/23 jQuery
原生JS实现小小的音乐播放器
2017/10/16 Javascript
vue基于mint-ui实现城市选择三级联动
2020/06/30 Javascript
微信小程序用户信息encryptedData详解
2018/08/24 Javascript
使用javascript做时间倒数读秒功能的实例
2019/01/23 Javascript
Vue3 响应式侦听与计算的实现
2020/11/11 Javascript
浅谈python3.6的tkinter运行问题
2019/02/22 Python
python学习——内置函数、数据结构、标准库的技巧(推荐)
2019/04/18 Python
Python脚本如何在bilibili中查找弹幕发送者
2020/06/04 Python
Python实现我的世界小游戏源代码
2021/03/02 Python
CSS3动画和HTML5新特性详解
2020/08/31 HTML / CSS
HTML5 Canvas玩转酷炫大波浪进度图效果实例(附demo)
2016/12/14 HTML / CSS
企业承诺书格式范文
2015/04/28 职场文书
2015年惩防体系建设工作总结
2015/05/22 职场文书
详解RedisTemplate下Redis分布式锁引发的系列问题
2021/04/27 Redis
PyTorch dropout设置训练和测试模式的实现
2021/05/27 Python
Mysql中调试存储过程最简单的方法
2021/06/30 MySQL
Python保存并浏览用户的历史记录
2022/04/29 Python
Rust中的Struct使用示例详解
2022/08/14 Javascript
CSS中理解层叠性及权重如何分配
2022/12/24 HTML / CSS