欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于vue實(shí)現(xiàn)探探滑動(dòng)組件功能

 更新時(shí)間:2020年05月29日 10:09:18   作者:javascript癡癡  
這篇文章主要介紹了基于vue實(shí)現(xiàn)探探滑動(dòng)組件功能,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

前言

嗨,說起探探想必各位程序汪都不陌生(畢竟妹子很多),能在上面絲滑的翻牌子,探探的的堆疊滑動(dòng)組件起到了關(guān)鍵的作用,下面就來看看如何用vue寫一個(gè)探探的堆疊組件 ?

一. 功能分析

簡(jiǎn)單使用下探探會(huì)發(fā)現(xiàn),堆疊滑動(dòng)的功能很簡(jiǎn)單,用一張圖概括就是:

簡(jiǎn)單歸納下里面包含的基本功能點(diǎn):

  • 圖片的堆疊
  • 圖片第一張的滑動(dòng)
  • 條件成功后的滑出,條件失敗后的回彈
  • 滑出后下一張圖片堆疊到頂部

體驗(yàn)優(yōu)化

根據(jù)觸摸點(diǎn)的不同,滑動(dòng)時(shí)首圖有不同角度偏移

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

二. 具體實(shí)現(xiàn)

有了歸納好的功能點(diǎn),我們實(shí)現(xiàn)組件的思路會(huì)更清晰

1. 堆疊效果

堆疊圖片效果在網(wǎng)上有大量的實(shí)例,實(shí)現(xiàn)的方法大同小異,主要通過在父層設(shè)定perspective及perspective-origin,來實(shí)現(xiàn)子層的透視,子層設(shè)定好translate3d Z軸數(shù)值即可模擬出堆疊效果,具體代碼如下

// 圖片堆疊dom
 <!--opacity: 0 隱藏我們不想看到的stack-item層級(jí)-->
 <!--z-index: -1 調(diào)整stack-item層級(jí)"-->
<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>

上面只是一組靜態(tài)代碼,我們希望得到的是vue組件,所以需要先建立一個(gè)組件模板stack.vue,在模板中我們可以使用v-for,遍歷出stack節(jié)點(diǎn),使用:style 來修改各個(gè)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數(shù)據(jù)包含基礎(chǔ)的圖片數(shù)據(jù)
  pages: {
   type: Array,
   default: []
  }
 },
 data () {
  return {
   // basicdata數(shù)據(jù)包含組件基本數(shù)據(jù)
   basicdata: {
    currentPage: 0 // 默認(rèn)首圖的序列
   },
   // temporaryData數(shù)據(jù)包含組件臨時(shí)數(shù)據(jù)
   temporaryData: {
    opacity: 1, // 記錄opacity
    zIndex: 10, // 記錄zIndex
    visible: 3 // 記錄默認(rèn)顯示堆疊數(shù)visible
   }
  }
 },
 methods: {
  // 遍歷樣式
  transform (index) {
   if (index >= this.basicdata.currentPage) {
    let style = {}
    let visible = this.temporaryData.visible
    let perIndex = index - this.basicdata.currentPage
    // visible可見數(shù)量前滑塊的樣式
    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>

關(guān)鍵點(diǎn)

style可以綁定對(duì)象的同時(shí),也可以綁定數(shù)組和函數(shù),這在遍歷的時(shí)候很有用

最基本的dom結(jié)構(gòu)已經(jīng)構(gòu)建完畢,下一步是讓首張圖片“動(dòng)”起來

2. 圖片滑動(dòng)

圖片滑動(dòng)效果,在很多場(chǎng)景中都有出現(xiàn),其原理無非是監(jiān)聽touchs事件,得到位移,再通過translate3D改變目標(biāo)位移,因此我們要實(shí)現(xiàn)的步驟如下

  • 對(duì)stack進(jìn)行touchs事件的綁定
  • 監(jiān)聽并儲(chǔ)存手勢(shì)位置變化的數(shù)值
  • 改變首圖css屬性中translate3D的x,y值

具體實(shí)現(xiàn)

在vue框架中,不建議直接操作節(jié)點(diǎn),而是通過指令v-on對(duì)元素進(jìn)行綁定,因此我們將綁定都寫在v-for遍歷里,通過index進(jìn)行判斷其是否是首圖,再使用: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數(shù)據(jù)包含基礎(chǔ)的圖片數(shù)據(jù)
  pages: {
   type: Array,
   default: []
  }
 },
 data () {
  return {
   // basicdata數(shù)據(jù)包含組件基本數(shù)據(jù)
   basicdata: {
    start: {}, // 記錄起始位置
    end: {}, // 記錄終點(diǎn)位置
    currentPage: 0 // 默認(rèn)首圖的序列
   },
   // temporaryData數(shù)據(jù)包含組件臨時(shí)數(shù)據(jù)
   temporaryData: {
    poswidth: '', // 記錄位移
    posheight: '', // 記錄位移
    tracking: false // 是否在滑動(dòng),防止多次操作,影響體驗(yàn)
   }
  }
 },
 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) {
   // 記錄滑動(dòng)位置
   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
    }
    // 計(jì)算滑動(dòng)值
    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
   // 滑動(dòng)結(jié)束,觸發(fā)判斷
  },
  // 非首頁樣式切換
  transform (index) {
   if (index > this.basicdata.currentPage) {
    let style = {}
    let visible = 3
    let perIndex = index - this.basicdata.currentPage
    // visible可見數(shù)量前滑塊的樣式
    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. 條件成功后的滑出,條件失敗后的回彈

條件的觸發(fā)判斷是在touchend/mouseup后進(jìn)行,在這里我們先用簡(jiǎn)單的條件進(jìn)行判定,同時(shí)給予首圖彈出及回彈的效果,代碼如下

<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數(shù)據(jù)包含基礎(chǔ)的圖片數(shù)據(jù)
  pages: {
   type: Array,
   default: []
  }
 },
 data () {
  return {
   // basicdata數(shù)據(jù)包含組件基本數(shù)據(jù)
   basicdata: {
    start: {}, // 記錄起始位置
    end: {}, // 記錄終點(diǎn)位置
    currentPage: 0 // 默認(rèn)首圖的序列
   },
   // temporaryData數(shù)據(jù)包含組件臨時(shí)數(shù)據(jù)
   temporaryData: {
    poswidth: '', // 記錄位移
    posheight: '', // 記錄位移
    tracking: false, // 是否在滑動(dòng),防止多次操作,影響體驗(yàn)
    animation: false, // 首圖是否啟用動(dòng)畫效果,默認(rèn)為否
    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) {
   // 記錄滑動(dòng)位置
   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
    }
    // 計(jì)算滑動(dòng)值
    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
   // 滑動(dòng)結(jié)束,觸發(fā)判斷
   // 簡(jiǎn)單判斷滑動(dòng)寬度超出100像素時(shí)觸發(fā)滑出
   if (Math.abs(this.temporaryData.poswidth) >= 100) {
    // 最終位移簡(jiǎn)單設(shè)定為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可見數(shù)量前滑塊的樣式
    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. 滑出后下一張圖片堆疊到頂部

重新堆疊是組件最后一個(gè)功能,同時(shí)也是最重要和復(fù)雜的功能。在我們的代碼里,stack-item的排序依賴綁定:style的transformIndex和transform函數(shù),函數(shù)里判定的條件是currentPage,那是不是改變currentPage,讓其+1,即可完成重新堆疊呢?

答案沒有那么簡(jiǎn)單,因?yàn)槲覀兓鍪莿?dòng)畫效果,會(huì)進(jìn)行300ms的時(shí)間,而currentPage變化引起的重排,會(huì)立即變化,打斷動(dòng)畫的進(jìn)行。因此我們需要先修改transform函數(shù)的排序條件,后改變currentPage。

具體實(shí)現(xiàn)

  • 修改transform函數(shù)排序條件
  • 讓currentPage+1
  • 添加onTransitionEnd事件,在滑出結(jié)束后,重新放置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數(shù)據(jù)包含基礎(chǔ)的圖片數(shù)據(jù)
  pages: {
   type: Array,
   default: []
  }
 },
 data () {
  return {
   // basicdata數(shù)據(jù)包含組件基本數(shù)據(jù)
   basicdata: {
    start: {}, // 記錄起始位置
    end: {}, // 記錄終點(diǎn)位置
    currentPage: 0 // 默認(rèn)首圖的序列
   },
   // temporaryData數(shù)據(jù)包含組件臨時(shí)數(shù)據(jù)
   temporaryData: {
    poswidth: '', // 記錄位移
    posheight: '', // 記錄位移
    lastPosWidth: '', // 記錄上次最終位移
    lastPosHeight: '', // 記錄上次最終位移
    tracking: false, // 是否在滑動(dòng),防止多次操作,影響體驗(yàn)
    animation: false, // 首圖是否啟用動(dòng)畫效果,默認(rèn)為否
    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) {
   // 記錄滑動(dòng)位置
   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
    }
    // 計(jì)算滑動(dòng)值
    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
   // 滑動(dòng)結(jié)束,觸發(fā)判斷
   // 簡(jiǎn)單判斷滑動(dòng)寬度超出100像素時(shí)觸發(fā)滑出
   if (Math.abs(this.temporaryData.poswidth) >= 100) {
    // 最終位移簡(jiǎn)單設(shè)定為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
    // 記錄最終滑動(dòng)距離
    this.temporaryData.lastPosWidth = this.temporaryData.poswidth
    this.temporaryData.lastPosHeight = this.temporaryData.posheight
    // currentPage+1 引發(fā)排序變化
    this.basicdata.currentPage += 1
    // currentPage切換,整體dom進(jìn)行變化,把第一層滑動(dòng)置零
    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發(fā)生變化后,正在執(zhí)行的動(dòng)畫滑動(dòng)序列已經(jīng)變?yōu)樯弦粚?
   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可見數(shù)量前滑塊的樣式
    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
   // 已滑動(dòng)模塊釋放后
   } else if (index === this.basicdata.currentPage - 1) {
    let style = {}
    // 繼續(xù)執(zhí)行動(dòng)畫
    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~ 完成了上面的四步,堆疊組件的基本功能就已經(jīng)實(shí)現(xiàn),快來看看效果吧

堆疊滑動(dòng)效果已經(jīng)出來了,但是探探在體驗(yàn)上,還增加了觸碰角度偏移,以及判定滑出面積比例

角度偏移的原理,是在用戶每次進(jìn)行touch時(shí),記錄用戶觸碰位置,計(jì)算出最大的偏移角度,在滑動(dòng)出現(xiàn)位移時(shí),線性增加角度以至最大的偏移角度。

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

touchmove中計(jì)算出所需角度和方向

touchend及onTransitionEnd中將角度至零

判定滑出面積比例,主要通過偏移量計(jì)算出偏移面積,從而得到面積比例,完成判斷

完整的代碼和demo可以在github上查看源碼,這里就不貼出來了

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue之計(jì)算屬性詳解

    Vue之計(jì)算屬性詳解

    這篇文章主要為大家介紹了Vue的計(jì)算屬性,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-11-11
  • vue3 高德地圖關(guān)鍵詞搜索獲取經(jīng)緯度的示例代碼

    vue3 高德地圖關(guān)鍵詞搜索獲取經(jīng)緯度的示例代碼

    這篇文章主要介紹了vue3 高德地圖關(guān)鍵詞搜索獲取經(jīng)緯度的示例代碼,需要的朋友可以參考下
    2024-08-08
  • Vue按照順序?qū)崿F(xiàn)多級(jí)彈窗效果 附Demo

    Vue按照順序?qū)崿F(xiàn)多級(jí)彈窗效果 附Demo

    這篇文章主要介紹了Vue按照順序?qū)崿F(xiàn)多級(jí)彈窗效果 附Demo,通過實(shí)例代碼介紹了單個(gè)彈窗和多級(jí)彈窗的實(shí)現(xiàn)方法,感興趣的朋友跟隨小編一起看看吧
    2024-05-05
  • nuxt.js框架使用小結(jié)

    nuxt.js框架使用小結(jié)

    本文主要介紹了nuxt.js框架使用小結(jié),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-08-08
  • vue-cli+webpack在生成的項(xiàng)目中使用bootstrap實(shí)例代碼

    vue-cli+webpack在生成的項(xiàng)目中使用bootstrap實(shí)例代碼

    本篇文章主要介紹了vue-cli+webpack在生成的項(xiàng)目中使用bootstrap實(shí)例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下
    2017-05-05
  • vue.js框架實(shí)現(xiàn)表單排序和分頁效果

    vue.js框架實(shí)現(xiàn)表單排序和分頁效果

    這篇文章主要為大家詳細(xì)介紹了vue.js框架實(shí)現(xiàn)表單排序和分頁效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • 詳解VUE中的插值( Interpolation)語法

    詳解VUE中的插值( Interpolation)語法

    這篇文章主要介紹了詳解VUE中的插值( Interpolation)語法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • vue實(shí)現(xiàn)的雙向數(shù)據(jù)綁定操作示例

    vue實(shí)現(xiàn)的雙向數(shù)據(jù)綁定操作示例

    這篇文章主要介紹了vue實(shí)現(xiàn)的雙向數(shù)據(jù)綁定操作,結(jié)合完整實(shí)例形式較為詳細(xì)的分析了vue.js進(jìn)行數(shù)據(jù)雙向綁定操作的常見實(shí)現(xiàn)方法與相關(guān)操作技巧,需要的朋友可以參考下
    2018-12-12
  • vue3組件化開發(fā)常用API知識(shí)點(diǎn)總結(jié)

    vue3組件化開發(fā)常用API知識(shí)點(diǎn)總結(jié)

    Vue是目前Web前端最流行的開發(fā)框架技術(shù),?下面這篇文章主要給大家介紹了關(guān)于vue3組件化開發(fā)常用API的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • Element el-button 按鈕組件的使用詳解

    Element el-button 按鈕組件的使用詳解

    這篇文章主要介紹了Element el-button 按鈕組件的使用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02

最新評(píng)論