Browse Source

优化slide

pull/19/head
zyronon 4 years ago
parent
commit
d1644335f6
  1. BIN
      src/assets/img/icon/components/share/bizhi.png
  2. BIN
      src/assets/img/icon/components/share/collectYellow.png
  3. BIN
      src/assets/img/icon/components/share/comeon.png
  4. BIN
      src/assets/img/icon/components/share/copyLink.png
  5. BIN
      src/assets/img/icon/components/share/copyPassword.png
  6. BIN
      src/assets/img/icon/components/share/dou.png
  7. BIN
      src/assets/img/icon/components/share/duoshan.png
  8. BIN
      src/assets/img/icon/components/share/qq.png
  9. BIN
      src/assets/img/icon/components/share/report.png
  10. BIN
      src/assets/img/icon/components/share/totoutiao.png
  11. BIN
      src/assets/img/icon/components/share/weChat.png
  12. BIN
      src/assets/img/icon/components/share/weChatZone.png
  13. 1
      src/pages/test/TestSlide.vue
  14. 91
      src/pages/test/slide.js

BIN
src/assets/img/icon/components/share/bizhi.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
src/assets/img/icon/components/share/collectYellow.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
src/assets/img/icon/components/share/comeon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
src/assets/img/icon/components/share/copyLink.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
src/assets/img/icon/components/share/copyPassword.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
src/assets/img/icon/components/share/dou.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
src/assets/img/icon/components/share/duoshan.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

BIN
src/assets/img/icon/components/share/qq.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
src/assets/img/icon/components/share/report.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

BIN
src/assets/img/icon/components/share/totoutiao.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
src/assets/img/icon/components/share/weChat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

BIN
src/assets/img/icon/components/share/weChatZone.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

1
src/pages/test/TestSlide.vue

@ -69,6 +69,7 @@ export default { @@ -69,6 +69,7 @@ export default {
.slide-list {
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
position: relative;

91
src/pages/test/slide.js

@ -3,24 +3,46 @@ import * as Vue from "vue"; @@ -3,24 +3,46 @@ import * as Vue from "vue";
export default class Slide {
constructor(id, config) {
let container = new Dom(id)
this.wrapper = new Dom().create('<div class="slide-wrapper"></div>')
this.list = new Dom().create('<div class="slide-list"></div>')
this.list.on('touchstart', this.touchstart.bind(this))
this.list.on('touchmove', this.touchmove.bind(this))
this.list.on('touchend', this.touchend)
this.wrapper.append(this.list)
container.append(this.wrapper)
this.wrapper = this.create('<div class="slide-wrapper"></div>')
this.list = this.create('<div class="slide-list"></div>')
this.list.addEventListener('touchstart', this.touchstart.bind(this))
this.list.addEventListener('touchmove', this.touchmove.bind(this))
this.list.addEventListener('touchend', this.touchend.bind(this))
this.wrapper.appendChild(this.list)
new Dom(id).append(new Dom(this.wrapper))
// let container = document.querySelector(id)
// console.log(container)
// container.appendChild(this.wrapper)
this.totalSize = 52
this.pageSize = 10
this.pageNo = 0
this.judgeValue = 0
this.currentIndex = 0
this.startTime = 0
this.startLocationX = 0
this.startLocationY = 0
this.moveXDistance = 0
this.moveYDistance = 0
this.height = 812
this.isDrawDown = true
this.config = config
this.appInsMap = new Map()
this.getData()
}
console.log(this.list)
create(template) {
let tempNode = document.createElement('div');
tempNode.innerHTML = template.trim();
return tempNode.firstChild;
}
css(el, ...args) {
el.style[args[0]] = args[1]
}
async getData() {
@ -29,9 +51,9 @@ export default class Slide { @@ -29,9 +51,9 @@ export default class Slide {
if (res.code === 200) {
res.data.list.map((v, i) => {
let el = this.getInsEl(v, i, false)
let item = new Dom().create('<div class="slide-item"></div>')
item.append(new Dom(el))
this.list.append(item)
let item = this.create('<div class="slide-item"></div>')
item.appendChild(el)
this.list.appendChild(item)
})
}
}
@ -57,6 +79,9 @@ export default class Slide { @@ -57,6 +79,9 @@ export default class Slide {
this.startLocationX = e.touches[0].pageX
this.startLocationY = e.touches[0].pageY
this.startTime = Date.now()
console.log('touchstart', this.startTime)
this.css(this.list, 'transition-duration', '0ms')
}
touchmove(e) {
@ -65,16 +90,50 @@ export default class Slide { @@ -65,16 +90,50 @@ export default class Slide {
// console.log('touchmove', this.moveXDistance)
// console.log('touchmove', this.moveYDistance)
this.list.css('transform', `translate3d(0,100px,0)`)
this.list.css('transform', `translate3d(0px, ${
this.moveYDistance +
this.css(this.list, 'transform', `translate3d(0px, ${
this.getHeight() + this.moveYDistance +
(this.isDrawDown ? this.judgeValue : -this.judgeValue)
}px, 0px)`)
}
getHeight() {
return -this.currentIndex * this.height
}
touchend() {
console.log('touchend')
let endTime = Date.now()
let gapTime = endTime - this.startTime
if (Math.abs(this.moveYDistance) < 20) gapTime = 1000
if (Math.abs(this.moveYDistance) > (this.height / 3)) gapTime = 100
// console.log(gapTime)
this.currentIndex += 1
console.log('currentIndex', this.currentIndex)
this.css(this.list, 'transition-duration', '300ms')
this.css(this.list, 'transform', `translate3d(0px, ${
this.getHeight()
}px, 0px)`)
return
if (gapTime < 150) {
if (this.isDrawDown) {
this.currentIndex += 1
} else {
this.currentIndex -= 1
}
console.log(1)
this.currentIndex += 1
this.css(this.list, 'transition-duration', '300ms')
this.css(this.list, 'transform', `translate3d(0px, ${
this.currentIndex * this.height
}px, 0px)`)
}
}
}
Loading…
Cancel
Save