基于vue实现探探滑动组件功能

前言

嗨,说起探探想必各位程序汪都不陌生(毕竟妹子很多),能在上面丝滑的翻牌子,探探的的堆叠滑动组件起到了关键的作用,下面就来看看如何用vue写一个探探的堆叠组件 ?

一. 功能分析

简单使用下探探会发现,堆叠滑动的功能很简单,用一张图概括就是:

简单归纳下里面包含的基本功能点:

  • 图片的堆叠
  • 图片第一张的滑动
  • 条件成功后的滑出,条件失败后的回弹
  • 滑出后下一张图片堆叠到顶部

体验优化

根据触摸点的不同,滑动时首图有不同角度偏移

偏移面积判定是否成功滑出

二. 具体实现

有了归纳好的功能点,我们实现组件的思路会更清晰

1. 堆叠效果

堆叠图片效果在网上有大量的实例,实现的方法大同小异,主要通过在父层设定perspective及perspective-origin,来实现子层的透视,子层设定好translate3d Z轴数值即可模拟出堆叠效果,具体代码如下

// 图片堆叠dom
 <!--opacity: 0 隐藏我们不想看到的stack-item层级-->
 <!--z-index: -1 调整stack-item层级"-->
<ul class="stack">
 <li class="stack-item" style="transform: translate3d(0px, 0px, 0px);opacity: 1;z-index: 10;"><img src="1.png" alt="01"></li>
 <li class="stack-item" style="transform: translate3d(0px, 0px, -60px);opacity: 1;z-index: 1"><img src="2.png" alt="02"></li>
 <li class="stack-item" style="transform: translate3d(0px, 0px, -120px);opacity: 1;z-index: 1"><img src="3.png" alt="03"></li>
 <li class="stack-item" style="transform: translate3d(0px, 0px, -180px);opacity: 0;z-index: -1"><img src="4.png" alt="04"></li>
 <li class="stack-item" style="transform: translate3d(0px, 0px, -180px);opacity: 0;z-index: -1"><img src="5.png" alt="05"></li>
</ul>
<style>
.stack {
  width: 100%;
  height: 100%;
  position: relative;
  perspective: 1000px; //子元素视距
  perspective-origin: 50% 150%; //子元素透视位置
  -webkit-perspective: 1000px;
  -webkit-perspective-origin: 50% 150%;
  margin: 0;
  padding: 0;
 }
 .stack-item{
  background: #fff;
  height: 100%;
  width: 100%;
  border-radius: 4px;
  text-align: center;
  overflow: hidden;
 }
 .stack-item img {
  width: 100%;
  display: block;
  pointer-events: none;
 }
</style>

上面只是一组静态代码,我们希望得到的是vue组件,所以需要先建立一个组件模板stack.vue,在模板中我们可以使用v-for,遍历出stack节点,使用:style 来修改各个item的style,代码如下

<template>
  <ul class="stack">
   <li class="stack-item" v-for="(item, index) in pages" :style="[transform(index)]">
    <img :src="item.src">
   </li>
  </ul>
</template>
<script>
export default {
 props: {
  // pages数据包含基础的图片数据
  pages: {
   type: Array,
   default: []
  }
 },
 data () {
  return {
   // basicdata数据包含组件基本数据
   basicdata: {
    currentPage: 0 // 默认首图的序列
   },
   // temporaryData数据包含组件临时数据
   temporaryData: {
    opacity: 1, // 记录opacity
    zIndex: 10, // 记录zIndex
    visible: 3 // 记录默认显示堆叠数visible
   }
  }
 },
 methods: {
  // 遍历样式
  transform (index) {
   if (index >= this.basicdata.currentPage) {
    let style = {}
    let visible = this.temporaryData.visible
    let perIndex = index - this.basicdata.currentPage
    // visible可见数量前滑块的样式
    if (index <= this.basicdata.currentPage + visible - 1) {
     style['opacity'] = '1'
     style['transform'] = 'translate3D(0,0,' + -1 * perIndex * 60 + 'px' + ')'
     style['zIndex'] = visible - index + this.basicdata.currentPage
     style['transitionTimingFunction'] = 'ease'
     style['transitionDuration'] = 300 + 'ms'
    } else {
     style['zIndex'] = '-1'
     style['transform'] = 'translate3D(0,0,' + -1 * visible * 60 + 'px' + ')'
    }
    return style
   }
  }
 }
}
</script>

关键点

style可以绑定对象的同时,也可以绑定数组和函数,这在遍历的时候很有用

最基本的dom结构已经构建完毕,下一步是让首张图片“动”起来

2. 图片滑动

图片滑动效果,在很多场景中都有出现,其原理无非是监听touchs事件,得到位移,再通过translate3D改变目标位移,因此我们要实现的步骤如下

  • 对stack进行touchs事件的绑定
  • 监听并储存手势位置变化的数值
  • 改变首图css属性中translate3D的x,y值

具体实现

在vue框架中,不建议直接操作节点,而是通过指令v-on对元素进行绑定,因此我们将绑定都写在v-for遍历里,通过index进行判断其是否是首图,再使用:style修改首页的样式,具体代码如下:

<template>
  <ul class="stack">
   <li class="stack-item" v-for="(item, index) in pages"
   :style="[transformIndex(index),transform(index)]"
   @touchstart.stop.capture="touchstart"
   @touchmove.stop.capture="touchmove"
   @touchend.stop.capture="touchend"
   @mousedown.stop.capture="touchstart"
   @mouseup.stop.capture="touchend"
   @mousemove.stop.capture="touchmove">
    <img :src="item.src">
   </li>
  </ul>
</template>
<script>
export default {
 props: {
  // pages数据包含基础的图片数据
  pages: {
   type: Array,
   default: []
  }
 },
 data () {
  return {
   // basicdata数据包含组件基本数据
   basicdata: {
    start: {}, // 记录起始位置
    end: {}, // 记录终点位置
    currentPage: 0 // 默认首图的序列
   },
   // temporaryData数据包含组件临时数据
   temporaryData: {
    poswidth: '', // 记录位移
    posheight: '', // 记录位移
    tracking: false // 是否在滑动,防止多次操作,影响体验
   }
  }
 },
 methods: {
  touchstart (e) {
   if (this.temporaryData.tracking) {
    return
   }
   // 是否为touch
   if (e.type === 'touchstart') {
    if (e.touches.length > 1) {
     this.temporaryData.tracking = false
     return
    } else {
     // 记录起始位置
     this.basicdata.start.t = new Date().getTime()
     this.basicdata.start.x = e.targetTouches[0].clientX
     this.basicdata.start.y = e.targetTouches[0].clientY
     this.basicdata.end.x = e.targetTouches[0].clientX
     this.basicdata.end.y = e.targetTouches[0].clientY
    }
   // pc操作
   } else {
    this.basicdata.start.t = new Date().getTime()
    this.basicdata.start.x = e.clientX
    this.basicdata.start.y = e.clientY
    this.basicdata.end.x = e.clientX
    this.basicdata.end.y = e.clientY
   }
   this.temporaryData.tracking = true
  },
  touchmove (e) {
   // 记录滑动位置
   if (this.temporaryData.tracking && !this.temporaryData.animation) {
    if (e.type === 'touchmove') {
     this.basicdata.end.x = e.targetTouches[0].clientX
     this.basicdata.end.y = e.targetTouches[0].clientY
    } else {
     this.basicdata.end.x = e.clientX
     this.basicdata.end.y = e.clientY
    }
    // 计算滑动值
    this.temporaryData.poswidth = this.basicdata.end.x - this.basicdata.start.x
    this.temporaryData.posheight = this.basicdata.end.y - this.basicdata.start.y
   }
  },
  touchend (e) {
   this.temporaryData.tracking = false
   // 滑动结束,触发判断
  },
  // 非首页样式切换
  transform (index) {
   if (index > this.basicdata.currentPage) {
    let style = {}
    let visible = 3
    let perIndex = index - this.basicdata.currentPage
    // visible可见数量前滑块的样式
    if (index <= this.basicdata.currentPage + visible - 1) {
     style['opacity'] = '1'
     style['transform'] = 'translate3D(0,0,' + -1 * perIndex * 60 + 'px' + ')'
     style['zIndex'] = visible - index + this.basicdata.currentPage
     style['transitionTimingFunction'] = 'ease'
     style['transitionDuration'] = 300 + 'ms'
    } else {
     style['zIndex'] = '-1'
     style['transform'] = 'translate3D(0,0,' + -1 * visible * 60 + 'px' + ')'
    }
    return style
   }
  },
  // 首页样式切换
  transformIndex (index) {
   // 处理3D效果
   if (index === this.basicdata.currentPage) {
    let style = {}
    style['transform'] = 'translate3D(' + this.temporaryData.poswidth + 'px' + ',' + this.temporaryData.posheight + 'px' + ',0px)'
    style['opacity'] = 1
    style['zIndex'] = 10
    return style
   }
  }
 }
}
</script>

3. 条件成功后的滑出,条件失败后的回弹

条件的触发判断是在touchend/mouseup后进行,在这里我们先用简单的条件进行判定,同时给予首图弹出及回弹的效果,代码如下

<template>
  <ul class="stack">
   <li class="stack-item" v-for="(item, index) in pages"
   :style="[transformIndex(index),transform(index)]"
   @touchmove.stop.capture="touchmove"
   @touchstart.stop.capture="touchstart"
   @touchend.stop.capture="touchend"
   @mousedown.stop.capture="touchstart"
   @mouseup.stop.capture="touchend"
   @mousemove.stop.capture="touchmove">
    <img :src="item.src">
   </li>
  </ul>
</template>
<script>
export default {
 props: {
   // pages数据包含基础的图片数据
  pages: {
   type: Array,
   default: []
  }
 },
 data () {
  return {
   // basicdata数据包含组件基本数据
   basicdata: {
    start: {}, // 记录起始位置
    end: {}, // 记录终点位置
    currentPage: 0 // 默认首图的序列
   },
   // temporaryData数据包含组件临时数据
   temporaryData: {
    poswidth: '', // 记录位移
    posheight: '', // 记录位移
    tracking: false, // 是否在滑动,防止多次操作,影响体验
    animation: false, // 首图是否启用动画效果,默认为否
    opacity: 1 // 记录首图透明度
   }
  }
 },
 methods: {
  touchstart (e) {
   if (this.temporaryData.tracking) {
    return
   }
   // 是否为touch
   if (e.type === 'touchstart') {
    if (e.touches.length > 1) {
     this.temporaryData.tracking = false
     return
    } else {
     // 记录起始位置
     this.basicdata.start.t = new Date().getTime()
     this.basicdata.start.x = e.targetTouches[0].clientX
     this.basicdata.start.y = e.targetTouches[0].clientY
     this.basicdata.end.x = e.targetTouches[0].clientX
     this.basicdata.end.y = e.targetTouches[0].clientY
    }
   // pc操作
   } else {
    this.basicdata.start.t = new Date().getTime()
    this.basicdata.start.x = e.clientX
    this.basicdata.start.y = e.clientY
    this.basicdata.end.x = e.clientX
    this.basicdata.end.y = e.clientY
   }
   this.temporaryData.tracking = true
   this.temporaryData.animation = false
  },
  touchmove (e) {
   // 记录滑动位置
   if (this.temporaryData.tracking && !this.temporaryData.animation) {
    if (e.type === 'touchmove') {
     this.basicdata.end.x = e.targetTouches[0].clientX
     this.basicdata.end.y = e.targetTouches[0].clientY
    } else {
     this.basicdata.end.x = e.clientX
     this.basicdata.end.y = e.clientY
    }
    // 计算滑动值
    this.temporaryData.poswidth = this.basicdata.end.x - this.basicdata.start.x
    this.temporaryData.posheight = this.basicdata.end.y - this.basicdata.start.y
   }
  },
  touchend (e) {
   this.temporaryData.tracking = false
   this.temporaryData.animation = true
   // 滑动结束,触发判断
   // 简单判断滑动宽度超出100像素时触发滑出
   if (Math.abs(this.temporaryData.poswidth) >= 100) {
    // 最终位移简单设定为x轴200像素的偏移
    let ratio = Math.abs(this.temporaryData.posheight / this.temporaryData.poswidth)
    this.temporaryData.poswidth = this.temporaryData.poswidth >= 0 ? this.temporaryData.poswidth + 200 : this.temporaryData.poswidth - 200
    this.temporaryData.posheight = this.temporaryData.posheight >= 0 ? Math.abs(this.temporaryData.poswidth * ratio) : -Math.abs(this.temporaryData.poswidth * ratio)
    this.temporaryData.opacity = 0
   // 不满足条件则滑入
   } else {
    this.temporaryData.poswidth = 0
    this.temporaryData.posheight = 0
   }
  },
  // 非首页样式切换
  transform (index) {
   if (index > this.basicdata.currentPage) {
    let style = {}
    let visible = 3
    let perIndex = index - this.basicdata.currentPage
    // visible可见数量前滑块的样式
    if (index <= this.basicdata.currentPage + visible - 1) {
     style['opacity'] = '1'
     style['transform'] = 'translate3D(0,0,' + -1 * perIndex * 60 + 'px' + ')'
     style['zIndex'] = visible - index + this.basicdata.currentPage
     style['transitionTimingFunction'] = 'ease'
     style['transitionDuration'] = 300 + 'ms'
    } else {
     style['zIndex'] = '-1'
     style['transform'] = 'translate3D(0,0,' + -1 * visible * 60 + 'px' + ')'
    }
    return style
   }
  },
  // 首页样式切换
  transformIndex (index) {
   // 处理3D效果
   if (index === this.basicdata.currentPage) {
    let style = {}
    style['transform'] = 'translate3D(' + this.temporaryData.poswidth + 'px' + ',' + this.temporaryData.posheight + 'px' + ',0px)'
    style['opacity'] = this.temporaryData.opacity
    style['zIndex'] = 10
    if (this.temporaryData.animation) {
     style['transitionTimingFunction'] = 'ease'
     style['transitionDuration'] = 300 + 'ms'
    }
    return style
   }
  }
 }
}
</script>

4. 滑出后下一张图片堆叠到顶部

重新堆叠是组件最后一个功能,同时也是最重要和复杂的功能。在我们的代码里,stack-item的排序依赖绑定:style的transformIndex和transform函数,函数里判定的条件是currentPage,那是不是改变currentPage,让其+1,即可完成重新堆叠呢?

答案没有那么简单,因为我们滑出是动画效果,会进行300ms的时间,而currentPage变化引起的重排,会立即变化,打断动画的进行。因此我们需要先修改transform函数的排序条件,后改变currentPage。

具体实现

  • 修改transform函数排序条件
  • 让currentPage+1
  • 添加onTransitionEnd事件,在滑出结束后,重新放置stack列表中

代码如下:

<template>
  <ul class="stack">
   <li class="stack-item" v-for="(item, index) in pages"
   :style="[transformIndex(index),transform(index)]"
   @touchmove.stop.capture="touchmove"
   @touchstart.stop.capture="touchstart"
   @touchend.stop.capture="touchend"
   @mousedown.stop.capture="touchstart"
   @mouseup.stop.capture="touchend"
   @mousemove.stop.capture="touchmove"
   @webkit-transition-end="onTransitionEnd"
   @transitionend="onTransitionEnd"
   >
    <img :src="item.src">
   </li>
  </ul>
</template>
<script>
export default {
 props: {
  // pages数据包含基础的图片数据
  pages: {
   type: Array,
   default: []
  }
 },
 data () {
  return {
   // basicdata数据包含组件基本数据
   basicdata: {
    start: {}, // 记录起始位置
    end: {}, // 记录终点位置
    currentPage: 0 // 默认首图的序列
   },
   // temporaryData数据包含组件临时数据
   temporaryData: {
    poswidth: '', // 记录位移
    posheight: '', // 记录位移
    lastPosWidth: '', // 记录上次最终位移
    lastPosHeight: '', // 记录上次最终位移
    tracking: false, // 是否在滑动,防止多次操作,影响体验
    animation: false, // 首图是否启用动画效果,默认为否
    opacity: 1, // 记录首图透明度
    swipe: false // onTransition判定条件
   }
  }
 },
 methods: {
  touchstart (e) {
   if (this.temporaryData.tracking) {
    return
   }
   // 是否为touch
   if (e.type === 'touchstart') {
    if (e.touches.length > 1) {
     this.temporaryData.tracking = false
     return
    } else {
     // 记录起始位置
     this.basicdata.start.t = new Date().getTime()
     this.basicdata.start.x = e.targetTouches[0].clientX
     this.basicdata.start.y = e.targetTouches[0].clientY
     this.basicdata.end.x = e.targetTouches[0].clientX
     this.basicdata.end.y = e.targetTouches[0].clientY
    }
   // pc操作
   } else {
    this.basicdata.start.t = new Date().getTime()
    this.basicdata.start.x = e.clientX
    this.basicdata.start.y = e.clientY
    this.basicdata.end.x = e.clientX
    this.basicdata.end.y = e.clientY
   }
   this.temporaryData.tracking = true
   this.temporaryData.animation = false
  },
  touchmove (e) {
   // 记录滑动位置
   if (this.temporaryData.tracking && !this.temporaryData.animation) {
    if (e.type === 'touchmove') {
     this.basicdata.end.x = e.targetTouches[0].clientX
     this.basicdata.end.y = e.targetTouches[0].clientY
    } else {
     this.basicdata.end.x = e.clientX
     this.basicdata.end.y = e.clientY
    }
    // 计算滑动值
    this.temporaryData.poswidth = this.basicdata.end.x - this.basicdata.start.x
    this.temporaryData.posheight = this.basicdata.end.y - this.basicdata.start.y
   }
  },
  touchend (e) {
   this.temporaryData.tracking = false
   this.temporaryData.animation = true
   // 滑动结束,触发判断
   // 简单判断滑动宽度超出100像素时触发滑出
   if (Math.abs(this.temporaryData.poswidth) >= 100) {
    // 最终位移简单设定为x轴200像素的偏移
    let ratio = Math.abs(this.temporaryData.posheight / this.temporaryData.poswidth)
    this.temporaryData.poswidth = this.temporaryData.poswidth >= 0 ? this.temporaryData.poswidth + 200 : this.temporaryData.poswidth - 200
    this.temporaryData.posheight = this.temporaryData.posheight >= 0 ? Math.abs(this.temporaryData.poswidth * ratio) : -Math.abs(this.temporaryData.poswidth * ratio)
    this.temporaryData.opacity = 0
    this.temporaryData.swipe = true
    // 记录最终滑动距离
    this.temporaryData.lastPosWidth = this.temporaryData.poswidth
    this.temporaryData.lastPosHeight = this.temporaryData.posheight
    // currentPage+1 引发排序变化
    this.basicdata.currentPage += 1
    // currentPage切换,整体dom进行变化,把第一层滑动置零
    this.$nextTick(() => {
     this.temporaryData.poswidth = 0
     this.temporaryData.posheight = 0
     this.temporaryData.opacity = 1
    })
   // 不满足条件则滑入
   } else {
    this.temporaryData.poswidth = 0
    this.temporaryData.posheight = 0
    this.temporaryData.swipe = false
   }
  },
  onTransitionEnd (index) {
   // dom发生变化后,正在执行的动画滑动序列已经变为上一层
   if (this.temporaryData.swipe && index === this.basicdata.currentPage - 1) {
    this.temporaryData.animation = true
    this.temporaryData.lastPosWidth = 0
    this.temporaryData.lastPosHeight = 0
    this.temporaryData.swipe = false
   }
  },
  // 非首页样式切换
  transform (index) {
   if (index > this.basicdata.currentPage) {
    let style = {}
    let visible = 3
    let perIndex = index - this.basicdata.currentPage
    // visible可见数量前滑块的样式
    if (index <= this.basicdata.currentPage + visible - 1) {
     style['opacity'] = '1'
     style['transform'] = 'translate3D(0,0,' + -1 * perIndex * 60 + 'px' + ')'
     style['zIndex'] = visible - index + this.basicdata.currentPage
     style['transitionTimingFunction'] = 'ease'
     style['transitionDuration'] = 300 + 'ms'
    } else {
     style['zIndex'] = '-1'
     style['transform'] = 'translate3D(0,0,' + -1 * visible * 60 + 'px' + ')'
    }
    return style
   // 已滑动模块释放后
   } else if (index === this.basicdata.currentPage - 1) {
    let style = {}
    // 继续执行动画
    style['transform'] = 'translate3D(' + this.temporaryData.lastPosWidth + 'px' + ',' + this.temporaryData.lastPosHeight + 'px' + ',0px)'
    style['opacity'] = '0'
    style['zIndex'] = '-1'
    style['transitionTimingFunction'] = 'ease'
    style['transitionDuration'] = 300 + 'ms'
    return style
   }
  },
  // 首页样式切换
  transformIndex (index) {
   // 处理3D效果
   if (index === this.basicdata.currentPage) {
    let style = {}
    style['transform'] = 'translate3D(' + this.temporaryData.poswidth + 'px' + ',' + this.temporaryData.posheight + 'px' + ',0px)'
    style['opacity'] = this.temporaryData.opacity
    style['zIndex'] = 10
    if (this.temporaryData.animation) {
     style['transitionTimingFunction'] = 'ease'
     style['transitionDuration'] = 300 + 'ms'
    }
    return style
   }
  }
 }
}
</script>

ok~ 完成了上面的四步,堆叠组件的基本功能就已经实现,快来看看效果吧

堆叠滑动效果已经出来了,但是探探在体验上,还增加了触碰角度偏移,以及判定滑出面积比例

角度偏移的原理,是在用户每次进行touch时,记录用户触碰位置,计算出最大的偏移角度,在滑动出现位移时,线性增加角度以至最大的偏移角度。

使用在stack中具体要做的是:

touchmove中计算出所需角度和方向

touchend及onTransitionEnd中将角度至零

判定滑出面积比例,主要通过偏移量计算出偏移面积,从而得到面积比例,完成判断

完整的代码和demo可以在github上查看源码,这里就不贴出来了

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

(0)

相关推荐

  • Vue 实现从小到大的横向滑动效果详解

    本文实例讲述了Vue 实现从小到大的横向滑动效果.分享给大家供大家参考,具体如下: 最近项目中遇到一个需求,需要实现横向滑动,并且在滑动过程中,中间的大,两边的小,通过参考其他的人代码以及自己的实践,终于做出来啦,给大家做个参考. 实现效果如下图: 先来说一下实现思路吧: 整体思路:采用vue+vue-awesome-swiper完成 因为我们的项目是采用vue来做的,所以在经过很多的考量和比较以后,选择了vue-awesome-swiper插件来辅助,从这个名字上也能看出,这个插件是支持vue

  • vue实现滑动到底部加载更多效果

    本文实例为大家分享了vue实现滑动到底部加载更多的具体代码,供大家参考,具体内容如下 思路: 如果可视区的高度域dom元素的getBoundingClientRect().bottom高度相同说明已经到了底部,可以实现加载了 template: <template> <div class="content"> <div class="logo"> <div> <img v-if="server[0].t

  • Vue实现滑动拼图验证码功能

    缘由:之前看哔哩哔哩官网登录的时候有一个拼图验证码,很好奇怎么去实现.然后就想着自己弄一个.先给大家看我的最终效果.后面再一点点拆解代码. 为什么想着写这个功能呢,主要在于拼图验证码在前端这里会比较复杂并且深入.相比文字拼写,12306的图片验证码都没有拼图验证码对前端的要求来的复杂,和难. 我总结下知识点: 1.弹窗功能 2.弹窗基于元素定位 3.元素拖动 4.canvas绘图 5.基础逻辑 一.弹窗和弹窗组件 抱歉,这里我偷懒了直接用了elementUI的el-popover组件,所以小伙伴

  • 使用Vue 实现滑动验证码功能

    做网络爬虫的同学肯定见过各种各样的验证码,比较高级的有滑动.点选等样式,看起来好像挺复杂的,但实际上它们的核心原理还是还是很清晰的,本文章大致说明下这些验证码的原理以及带大家实现一个滑动验证码. 我之前做过 Web 相关开发,尝试对接过 Lavavel 的极验验证,当时还开发了一个 Lavavel 包: https://github.com/Germey/LaravelGeetest ,在开发包的过程中了解到了验证码的两步校验规则. 实际上这类验证码的校验是分为两个步骤的: 1.第一步就是前端的

  • vue仿淘宝滑动验证码功能(样式模仿)

    我们知道验证码的目的 是为了验证到底是人还是机器. 淘宝滑动验证码会采集用户的操作数据,环境数据等等,通过算法加密成一个字符串,提交到服务器分析,判断是不是人工在操作. 我这里写的只是模仿了样式,并没有进行那些复杂的操作,所以并不安全(不能判断人还是机器). 因为touch事件和mouse事件不同,和获取clientX在移动端和pc端也不同!!!所以分两端 下面有PC端和移动端!!!(2019-03-12更新) 本文基于vue,引入下面组件 可以直接使用 1.实际效果 2.PC端!!! vue组

  • vue开发拖拽进度条滑动组件

    分享一个最近写的进度条滑动组件,以前都是用jq写,学会了vue,尝试着拿vue来写觉得非常简单,代码复用性很强! 效果图如下: 调用组件如下: <slider :min=0 :max=100 v-model = "per"></slider> <template> <div class="slider" ref="slider"> <div class="process"

  • vue + any-touch实现一个iscroll 实现拖拽和滑动动画效果

    https://github.com/383514580/any-touch 先看demo demo 说点湿的 iscroll其实代码量挺大的(近2100行, 还有另一个类似的库 betterScroll 他的代码量和iscroll差不多, 因为原理都是一样的), 阅读他们的代码 发现里面很多逻辑 其实都是在做手势判断 , 比如拖拽(pan), 和划(swipe), 还有部分元素(表单元素等)需要单独判断点击(tap), 这部分代码接近1/3, 所以我决定用自己开发的手势库(any-touch)

  • Vue插件之滑动验证码用法详解

    本文实例讲述了Vue插件之滑动验证码用法.分享给大家供大家参考,具体如下: 目录 预览 基于滑动式的验证码,免于字母验证码的繁琐输入 用于网页注册或者登录 安装 使用方法 更新记录 V1.1.2 版本 V1.1.1 描述(此版本有bug,请使用最新版) V1.1.0 版本新增属性`imgs`: 内置方法 props传参(均为可选) 自定义回调函数 注意事项 预览 基于滑动式的验证码,免于字母验证码的繁琐输入 用于网页注册或者登录 目前仅前端实现,支持移动端滑动事件.版本V1.1.2 github

  • Android开发中RecyclerView模仿探探左右滑动布局功能

    我在此基础上优化了部分代码, 添加了滑动回调, 可自定义性更强. 并且添加了点击按钮左右滑动的功能. 据说无图都不敢发文章了. 看图: 1:这种功能, 首先需要自己管理布局 继承 RecyclerView.LayoutManager , 显示自己管理布局, 比如最多显示4个view, 并且都是居中显示. 底部的View还需要进行缩放,平移操作. public class OverLayCardLayoutManager extends RecyclerView.LayoutManager { p

  • 基于cropper.js封装vue实现在线图片裁剪组件功能

    效果图如下所示, github:demo下载 cropper.js github:cropper.js 官网(demo) cropper.js 安装 npm或bower安装 npm install cropper # or bower install cropper clone下载:下载地址 git clone https://github.com/fengyuanchen/cropper.git 引用cropper.js 主要引用cropper.js跟cropper.css两个文件 <scri

  • 基于Vue的文字跑马灯组件(npm 组件包)

    一.前言 总结下最近工作上在移动端实现的一个跑马灯效果,最终效果如下: 印象中好像HTML标签的'marquee'的直接可以实现这个效果,不过 HTML标准中已经废弃了'marquee'标签 既然HTML标准已经废弃了这个标签,现在工作上用的是Vue,所以想着能不能自己也发布一个基于Vue的文字跑马灯组件包,这样别人可以通过npm install ...就可以用,想想还有点激动,于是开始我的第一个npm组件之旅! 二.用npm发布一个包 有点惭愧,之前通过npm install ...安装pac

  • 基于Vue制作组织架构树组件

    由于公司业务需求,需要开发一个展示组织架构的树组件(公司的项目是基于Vue).在GitHub上找了半天,这类组件不多,也没有符合业务需求的组件,所以决定自己造轮子! 分析 既然是树,那么每个节点都应该是相同的组件 节点下面套节点,所以节点组件应该是一个 递归组件 那么,问题来了.递归组件怎么写? 递归组件 Vue官方文档是这样说的: 组件在它的模板内可以递归地调用自己.不过,只有当它有 name 选项时才可以这么做 接下来,我们来写一个树节点递归组件: <template> <div c

  • Vue中添加手机验证码组件功能操作方法

    什么是组件: 组件是Vue.js最强大的功能之一.组件可以扩展HTML元素,封装可重用的代码.在较高层面上,组件是自定义的元素,Vue.js的编译器为它添加特殊功能.在有些情况下,组件也可以是原生HTML元素的形式,以is特性扩展. 写在前面: 今天要实现的功能是在 完善个人信息页面(vue)中添加手机验证码组件,当用户点击 手机选项时,弹出获取验证码组件,完成验证手机的功能: 这里考虑到功能的复用,我把当前弹出手机验证码的操作放在了单独的组件中: <template > <div>

  • 基于Vue实现Excel解析与导出功能详解

    目录 前言 基本介绍 代码实现 基本结构 上传解析 Excel的导出 基本结构 导出Excel 总结 前言 最近在整理日常开发中长涉及到的业务需求,正好想到了excel的解析与上传方面的事情,在开发中还是比较常见的,趁着周末做一下整理学习吧 基本介绍 主要基于Vue+element实现文件的解析与导出,用的的插件是 xlsx,里面的具体方法,感兴趣的去研究一下,基本的样式,配置就不赘述了,也比较简单,我们直接上主食 代码实现 基本结构 用户点击文件上传,将excel的表格已json的格式显示在页

  • 基于vue+ bootstrap实现图片上传图片展示功能

    效果图如下所示: html ..... ....... <-- key=idPicUrl --> <div class="col-sm-7" > <img :src="queryFirmInfo[key]" alt="" style="max-height:200px;max-width:250px" class="myimage" :name="key"

  • 基于Vue实现的多条件筛选功能的详解(类似京东和淘宝功能)

    基于Vue实现的多条件筛选功能(类似京东和淘宝功能),可以支持多选.清空.全选功能,数据源是通过JSon格式的数据封装而成. 实现的效果图: 代码实现如下: html: <div id='app'> <template v-if='condition.length'> <div> <span>已选中:<span> <span v-for='(item,index) in condition' class='active'>{{item

  • Vue 实现一个命令式弹窗组件功能

    前言 在日常工作中弹窗组件是很常用的组件,但用得多还是别人的,空闲时间就自己来简单实现一个弹窗组件 涉及知识点:extend.$mount.$el 使用方式: this.$Confirm({ title:'自定义标题' }).then(res=>{ console.log(res) }) 目录结构 index.vue:组件布局.样式.交互逻辑 index.js:挂载组件.暴露方法 知识点 在此之前,了解下涉及的知识点 1. extend 使用这个api,可以将引入的vue组件变成vue构造函数,

随机推荐