最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue swipe自定義組件實(shí)現(xiàn)輪播效果

 更新時(shí)間:2019年07月03日 08:37:00   作者:戴向天  
這篇文章主要為大家詳細(xì)介紹了vue swipe自定義組件實(shí)現(xiàn)輪播效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue swipe自定義組件實(shí)現(xiàn)輪播效果的具體代碼,供大家參考,具體內(nèi)容如下

<template>

 <layout-div :style="getStyle" class="over-h posi-r">
 <layout-div :style="getChildStyle" class="flex" @load="loadHandle">
  <slot/>
 </layout-div>
 <layout-div class="flex-center flex posi-a b0 l0 r0" :height="40" :unit="unit" v-if="!$slots.point">
  <layout-div class="flex">
  <layout-div v-for="i in this.length" :key="i" class="op-5" :mar="[0,15]" :height="20" :width="20"
    :bg="Math.abs(index) == i-1?'red':'#fff'" :fillet="20" :unit="unit"/>
  </layout-div>
 </layout-div>
 <slot v-else name="point"/>
 </layout-div>

</template>
<script>
 export default {
 props: {
  value: {
  type: Number,
  default: 0
  },
  width: { //寬
  type: Number,
  default: null
  },
  height: { //高
  type: Number,
  default: null,
  },
  unit: { //單位
  type: String,
  default: 'px'
  },
  time: { //時(shí)間(毫秒)
  type: Number,
  default: 3000
  },
  direction: { //方向 X | Y (注意是:大寫)
  type: String,
  default: "X"
  },
  duration: { //每次切換的時(shí)間(毫秒)
  type: Number,
  default: 300
  },
  autoPlay: { //是否自動(dòng)輪播
  type: Boolean,
  default: true
  }
 },
 data() {
  return {
  style: {},
  multiple: 50, //倍數(shù)處理,更加UI進(jìn)行 100倍是按照 750*1334 的UI
  dom: null,  //當(dāng)前swipe元素
  length: 0, //子元素的數(shù)量
  countWidth: 0, //總長度
  index: 0,
  isTouch: false,// 手指是否在屏幕上
  }
 },
 methods: {
  loadHandle(e) {
  this.dom = e.dom
  this.length = e.dom.childElementCount
  for (let i = 0; i < this.length; i++) {
   this.dom.children[i].style.height = this.height ? this.height / this.multiple + this.unit : ''
   this.dom.children[i].style.width = parseFloat(this.dom.style.width) / this.length / this.multiple + this.unit
   this.dom.children[i].style.flexGrow = 1;
  }
  this.bingTouch(this.dom)
  // 判斷可不可以自動(dòng)輪播
  if (this.autoPlay && this.length) this.beginSwipe()
  },
  bingTouch(dom) {
  const self = this;
  let tranX = 0
  this.touch({
   stop: false,
   dom,
   start(e) {
   dom.style.transitionDuration = '0ms'
   tranX = parseFloat(dom.style.transform.split("(")[1]) || 0
   },
   move({dx}) {
   dom.style.transform = `translateX(${dx + tranX + self.unit})`;
   },
   change({direction}) {
   switch (direction) {
    case 'left':
    self.index--;
    break;
   }
   self.moveHandle()
   }
  })
  },
  moveHandle() {  //移動(dòng)
  const Y = parseFloat(this.dom.style.width) / this.length
  this.dom.style.transitionDuration = `${this.duration}ms`
  this.dom.style.transform = `translateX(${this.index * Y + this.unit})`;
  setTimeout(() => {
   if (!this.isTouch) {
   if (Math.abs(this.index) == this.length - 1) {
    // console.log("要開始調(diào)換位置了");
    const first = this.dom.firstChild;
    first.style.transform = `translateX(${(Math.abs(-this.index) + 1) * Y + this.unit})`;
   } else if (Math.abs(this.index) == this.length) {
    // console.log("開始下一輪了")
    const first = this.dom.firstChild;
    this.dom.style.transitionDuration = '0ms'
    this.dom.style.transform = `translateX(${0 + this.unit})`;
    this.index = 0;
    first.style.transform = `translateX(${0 + this.unit})`;
   }
   }
   this.$emit('input', Math.abs(this.index))
  }, this.duration)
  },
  beginSwipe() {
  setTimeout(() => {
   if (this.isTouch) return this.beginSwipe(); //如果是手指在移動(dòng),就不再執(zhí)行
   this.index--
   this.moveHandle()
   this.beginSwipe()
  }, this.time > this.duration ? this.time : this.duration + 1000)
  }
 },
 computed: {
  getStyle() {
  if (this.unit != 'rem') this.multiple = 1;
  const width = this.width ? this.width / this.multiple + this.unit : '100%',
   height = this.height ? this.height / this.multiple + this.unit : ''
  return {width, height};
  },
  getChildStyle() {
  if (this.unit != 'rem') this.multiple = 1;
  this.countWidth = ((this.width || this.dom ? this.dom.parentNode.clientWidth : window.screen.width) / this.multiple * this.length)
  this.style.width = this.countWidth + this.unit
  if (this.height) {
   this.style.height = this.height / this.multiple + this.unit
  } else {
   this.style.height = ''
  }
  return this.style;
  }
 }
 }

</script>

class - style 具體內(nèi)容如下

css 參考的 UI設(shè)計(jì)尺寸為 750*1334

.over-h {
 overflow: hidden;
}
.posi-r {
 position: relative;
 z-index: 0;
}
.flex {
 display: flex;
}
.flex-center {
 justify-content: center;
 align-items: center;
}
.posi-a {
 position: absolute;
 z-index: 0;
}
.b0 {
 bottom: 0;
}

.l0 {
 left: 0;
}
.r0 {
 right: 0;
}
.op-5 {
 opacity: 0.5
}
.font-68 {
 font-size: 0.68rem;
}
.col-f {
 color: #fff;
}

示例代碼

 <layout-swipe :height="240" :time="2000" unit="rem">
  <layout-div bg="red" class="flex-center flex font-68 col-f">1</layout-div>
  <layout-div bg="yellow" class="flex-center flex font-68 col-f">2</layout-div>
  <layout-div bg="green" class="flex-center flex font-68 col-f">3</layout-div>
 </layout-swipe>

效果圖

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

相關(guān)文章

  • 詳解Vue文檔中幾個(gè)易忽視部分的剖析

    詳解Vue文檔中幾個(gè)易忽視部分的剖析

    針對(duì)Vue文檔中部分大家可能不會(huì)去研讀的內(nèi)容,這篇文章主要介紹了詳解Vue文檔中幾個(gè)易忽視部分的剖析,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2018-03-03
  • vite+vue3中如何使用router

    vite+vue3中如何使用router

    這篇文章主要介紹了vite+vue3中如何使用router問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • 使用 Vue.js 仿百度搜索框的實(shí)例代碼

    使用 Vue.js 仿百度搜索框的實(shí)例代碼

    本篇文章主要介紹了使用 Vue.js 仿百度搜索框的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-05-05
  • Vue3和Vite不得不說的那些事

    Vue3和Vite不得不說的那些事

    這篇文章主要為大家詳細(xì)介紹了Vue3和Vite的那些事,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-02-02
  • Vue通知提醒框(Notification)圖文詳解

    Vue通知提醒框(Notification)圖文詳解

    最近有個(gè)項(xiàng)目需求就是在客戶端的右上角要實(shí)時(shí)展示提醒消息,下面這篇文章主要給大家介紹了關(guān)于Vue通知提醒框(Notification)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-11-11
  • Vue computed與watch用法區(qū)分

    Vue computed與watch用法區(qū)分

    watch和computed都是以Vue的依賴追蹤機(jī)制為基礎(chǔ)的,當(dāng)某一個(gè)依賴型數(shù)據(jù)發(fā)生變化的時(shí)候,所有依賴這個(gè)數(shù)據(jù)的相關(guān)數(shù)據(jù)會(huì)自動(dòng)發(fā)生變化,即自動(dòng)調(diào)用相關(guān)的函數(shù),來實(shí)現(xiàn)數(shù)據(jù)的變動(dòng),這篇文章簡單介紹下Vue中computed和watch的區(qū)別異同,感興趣的朋友一起看看吧
    2023-02-02
  • vue圖片轉(zhuǎn)base64格式的方法示例

    vue圖片轉(zhuǎn)base64格式的方法示例

    對(duì)于前后端分離的項(xiàng)目,為了統(tǒng)一響應(yīng)參數(shù),需要將圖片轉(zhuǎn)換成base64的格式,下面這篇文章主要給大家介紹了關(guān)于vue圖片轉(zhuǎn)base64格式的相關(guān)資料,需要的朋友可以參考下
    2022-12-12
  • vue實(shí)現(xiàn)日歷表格(element-ui)

    vue實(shí)現(xiàn)日歷表格(element-ui)

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)日歷表格(element-ui),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • 淺談VUE uni-app 基礎(chǔ)組件

    淺談VUE uni-app 基礎(chǔ)組件

    這篇文章主要介紹了uni-app 的基礎(chǔ)組件,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-10-10
  • 說說如何使用Vuex進(jìn)行狀態(tài)管理(小結(jié))

    說說如何使用Vuex進(jìn)行狀態(tài)管理(小結(jié))

    這篇文章主要介紹了說說如何使用Vuex進(jìn)行狀態(tài)管理(小結(jié)),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04

最新評(píng)論

伊金霍洛旗| 萝北县| 萨迦县| 广宗县| 四子王旗| 鞍山市| 双鸭山市| 和顺县| 贡山| 辉南县| 民勤县| 化隆| 蒲江县| 宁都县| 高阳县| 合江县| 望奎县| 碌曲县| 建水县| 岳西县| 南江县| 秦皇岛市| 鄂伦春自治旗| 宁武县| 浏阳市| 民和| 定南县| 金川县| 阿拉善盟| 揭阳市| 彰化县| 青田县| 黄冈市| 五常市| 莱州市| 饶阳县| 西平县| 陆川县| 萨迦县| 泾川县| 九江县|