Browse Source

优化me页面

pull/19/head
zyronon 4 years ago
parent
commit
082eef17e7
  1. 2
      src/mock/index.js
  2. 259
      src/pages/me/Me2.vue

2
src/mock/index.js

@ -51,7 +51,7 @@ let pageSize = 15 @@ -51,7 +51,7 @@ let pageSize = 15
!(function my() {
// let data = {total: Mock.Random.natural(1, 20)}
// data[`list|${data.total > pageSize ? pageSize : data.total}`] = [{'like|10000-990000': 1000000, src: '@imgs'}]
let data = {total: 8}
let data = {total: 18}
data[`list|${data.total}`] = [{'like|10000-990000': 1000000, src: '@imgs'}]
Mock.mock(/my/, Mock.mock({data, code: 200, msg: '',}))
}())

259
src/pages/me/Me2.vue

@ -356,37 +356,19 @@ export default { @@ -356,37 +356,19 @@ export default {
(!this.isScroll) && e.preventDefault();
},
touchMove(e) {
//
let offsetTop = this.refs.descHeight - this.floatHeight
// console.log('pageY', e.touches[0].pageY)
// console.log('moveYDistance', this.moveYDistance)
let moveYDistance = e.touches[0].pageY - this.startLocationY
let distance = this.moveYDistance + moveYDistance * 1.2
// console.log('distance', distance)
//
if (distance > 0) {
this.$refs.scroll.style.transform = `translate3d(0,0,0)`
if (distance < 400) {
// if (this.baseActiveIndex !== 0) return
// if (this.refs.header.getBoundingClientRect().top !== 0) return
this.refs.header.style.transition = 'all 0s'
this.refs.header.style.height = this.refs.headerHeight + (distance / 2) + 'px'
} else {
this.startLocationY = e.touches[0].pageY
this.moveYDistance = 400
}
return
}
// console.log('s', e.touches[0].pageY - this.startLocationY)
// console.log('indicatorFixed', this.indicatorFixed)
let canTransformY = this.refs.descHeight - this.floatHeight
let touchMoveDistance = e.touches[0].pageY - this.startLocationY
let pageMoveDistance = this.moveYDistance + touchMoveDistance * 1.2
// console.log('move-pageMoveDistance', pageMoveDistance)
if (this.indicatorFixed) {
let SlideItems = document.querySelectorAll('.SlideItem')
let SlideItem = SlideItems[this.contentIndex]
// console.log(tt.scrollTop)
if (!this.isScroll) {
SlideItem.style.overflow = 'auto'
SlideItem.scrollTop = Math.abs(distance) - this.refs.descHeight + this.floatHeight
SlideItem.scrollTop = Math.abs(pageMoveDistance) - this.refs.descHeight + this.floatHeight
}
if (SlideItem.scrollTop === 0 && (e.touches[0].pageY - this.fixedLocationY) > 0) {
this.isScroll = this.indicatorFixed = false
@ -395,126 +377,149 @@ export default { @@ -395,126 +377,149 @@ export default {
this.moveYDistance = -this.refs.descHeight + this.floatHeight
}
} else {
this.indicatorFixed = Math.abs(distance) > offsetTop
if (this.indicatorFixed) {
this.fixedLocationY = e.touches[0].pageY
}
if (this.refs.defaultVideoSlideRowListHeight > this.refs.videoSlideRowListHeight) {
let endTransformY = Math.abs(offsetTop) - (this.refs.defaultVideoSlideRowListHeight - this.refs.videoSlideRowListHeight)
this.$refs.scroll.style.transform = `translate3d(0,${
distance > -endTransformY ? distance : -endTransformY
}px,0)`
this.floatFixed = Math.abs(distance) > 100
this.floatShowName = Math.abs(distance) > 150
if (pageMoveDistance > 0) {
this.$refs.scroll.style.transform = `translate3d(0,0,0)`
if (pageMoveDistance < 400) {
this.refs.header.style.transition = 'all 0s'
this.refs.header.style.height = this.refs.headerHeight + (pageMoveDistance / 2) + 'px'
} else {
this.startLocationY = e.touches[0].pageY
this.moveYDistance = 400
}
} else {
this.floatFixed = Math.abs(distance) > 100
this.floatShowName = Math.abs(distance) > 150
this.$refs.scroll.style.transform = `translate3d(0,${this.indicatorFixed ? -offsetTop : distance}px,0)`
if (this.refs.defaultVideoSlideRowListHeight > this.refs.videoSlideRowListHeight) {
let endTransformY = Math.abs(canTransformY) - (this.refs.defaultVideoSlideRowListHeight - this.refs.videoSlideRowListHeight)
this.$refs.scroll.style.transform = `translate3d(0,${
pageMoveDistance > -endTransformY ? pageMoveDistance : -endTransformY
}px,0)`
// this.floatFixed = Math.abs(pageMoveDistance) > 100
// this.floatShowName = Math.abs(pageMoveDistance) > 150
} else {
this.indicatorFixed = Math.abs(pageMoveDistance) > canTransformY
// this.floatFixed = Math.abs(pageMoveDistance) > 100
// this.floatShowName = Math.abs(pageMoveDistance) > 150
this.$refs.scroll.style.transform = `translate3d(0,${this.indicatorFixed ? -canTransformY : pageMoveDistance}px,0)`
}
if (this.indicatorFixed) {
this.fixedLocationY = e.touches[0].pageY
}
}
}
},
touchEnd(e) {
// console.log('this.startLocationY', this.startLocationY)
// debugger
let moveYDistance = e.changedTouches[0].pageY - this.startLocationY
this.moveYDistance = this.moveYDistance + moveYDistance * 1.2//1.2
// console.log('end-moveYDistance', this.moveYDistance)
//header
if (this.moveYDistance > 0) {
// if (this.baseActiveIndex !== 0) return
this.refs.header.style.transition = 'all .3s'
this.refs.header.style.height = this.refs.headerHeight + 'px'
this.moveYDistance = 0
this.floatShowName = this.floatFixed = this.isScroll = false
return
}
// console.log('header-height', this.refs.descHeight - this.floatHeight)
// this.isScroll = Math.abs(this.moveYDistance) > this.refs.descHeight - this.floatHeight
//
//
if (!this.indicatorFixed) {
//
let distance = e.changedTouches[0].pageY - this.startLocationY
// console.log('end-distance', distance)
let endTime = Date.now()
let gapTime = endTime - this.startTime
//
if (Math.abs(distance) < 20) gapTime = 1000
//header1/3
if (Math.abs(distance) > (this.refs.descHeight / 2)) gapTime = 50
// console.log('', gapTime)
if (gapTime < 150) {
//
if (distance > 0) {
//
gapTime = endTime - this.startTime
if (gapTime < 100 && Math.abs(distance) > 100) {
//cancelAnimationFrametransition = 'all .3s'
this.$refs.scroll.style.transition = 'none'
let transformY = this.getTransform(this.$refs.scroll)
//transformY
// console.log('transformY', transformY)
let timer
cancelAnimationFrame(timer);
let fn = () => {
//
if (transformY < 0) {
transformY = transformY + 40
this.$refs.scroll.style.transform = `translate3d(0,${transformY > 0 ? 0 : transformY}px,0)`
timer = requestAnimationFrame(fn);
} else {
//transformY === 0,
if (transformY !== 0) {
if (this.$getCss(this.refs.header, 'height') < 400) {
this.refs.header.style.transition = 'none'
this.refs.header.style.height = this.$getCss(this.refs.header, 'height') + 10 + 'px'
timer = requestAnimationFrame(fn);
let canTransformY = this.refs.descHeight - this.floatHeight
let touchMoveDistance = e.changedTouches[0].pageY - this.startLocationY
let pageMoveDistance = this.moveYDistance + touchMoveDistance * 1.2
let endTransformY = Math.abs(canTransformY) - (this.refs.defaultVideoSlideRowListHeight - this.refs.videoSlideRowListHeight)
if (this.indicatorFixed) {
this.moveYDistance = -canTransformY
this.isScroll = true
} else {
// debugger
if (pageMoveDistance > 0) {
this.refs.header.style.transition = 'all .3s'
this.refs.header.style.height = this.refs.headerHeight + 'px'
this.moveYDistance = 0
this.floatShowName = this.floatFixed = this.isScroll = false
} else {
let endTime = Date.now()
let gapTime = endTime - this.startTime
//
if (Math.abs(touchMoveDistance) < 20) gapTime = 1000
//header1/3
if (Math.abs(touchMoveDistance) > (this.refs.descHeight / 2)) gapTime = 50
// console.log('', gapTime)
if (gapTime < 150) {
//
if (touchMoveDistance > 0) {
//
gapTime = endTime - this.startTime
if (gapTime < 100 && Math.abs(touchMoveDistance) > 100) {
//cancelAnimationFrametransition = 'all .3s'
this.$refs.scroll.style.transition = 'none'
let transformY = this.getTransform(this.$refs.scroll)
//transformY
// console.log('transformY', transformY)
let timer
cancelAnimationFrame(timer);
let fn = () => {
//
if (transformY < 0) {
transformY = transformY + 40
this.$refs.scroll.style.transform = `translate3d(0,${transformY > 0 ? 0 : transformY}px,0)`
timer = requestAnimationFrame(fn);
} else {
//transformY === 0,
if (transformY !== 0) {
if (this.$getCss(this.refs.header, 'height') < 400) {
this.refs.header.style.transition = 'none'
this.refs.header.style.height = this.$getCss(this.refs.header, 'height') + 10 + 'px'
timer = requestAnimationFrame(fn);
} else {
this.refs.header.style.transition = 'all .6s'
this.refs.header.style.height = this.refs.headerHeight + 'px'
this.moveYDistance = 0
cancelAnimationFrame(timer);
}
} else {
this.refs.header.style.transition = 'all .6s'
this.refs.header.style.height = this.refs.headerHeight + 'px'
//
this.moveYDistance = 0
cancelAnimationFrame(timer);
}
} else {
//
this.moveYDistance = 0
cancelAnimationFrame(timer);
}
}
timer = requestAnimationFrame(fn);
} else {
//
this.$refs.scroll.style.transition = 'all .3s'
this.$refs.scroll.style.transform = `translate3d(0,${touchMoveDistance > 0 ? 0 : -this.refs.descHeight}px,0)`
this.moveYDistance = touchMoveDistance > 0 ? 0 : -this.refs.descHeight
}
timer = requestAnimationFrame(fn);
this.moveYDistance = 0
this.indicatorFixed = this.floatShowName = this.floatFixed = this.isScroll = false
this.changeIndex(this.contentIndex, this.contentIndex)
let SlideItems = document.querySelectorAll('.SlideItem')
// let SlideItem = SlideItems[this.contentIndex]
SlideItems.forEach(SlideItem => {
SlideItem.style.overflow = 'auto'
SlideItem.scrollTop = 0
})
SlideItems.forEach(SlideItem => {
SlideItem.style.overflow = 'hidden'
})
} else {
//
//
this.$refs.scroll.style.transition = 'all .3s'
this.$refs.scroll.style.transform = `translate3d(0,${distance > 0 ? 0 : -this.refs.descHeight}px,0)`
this.moveYDistance = distance > 0 ? 0 : -this.refs.descHeight
if (this.refs.defaultVideoSlideRowListHeight > this.refs.videoSlideRowListHeight) {
this.$refs.scroll.style.transform = `translate3d(0,${-endTransformY}px,0)`
// this.floatShowName = this.floatFixed = true
this.floatFixed = Math.abs(endTransformY) > 100
this.floatShowName = Math.abs(endTransformY) > 150
this.moveYDistance = -endTransformY
} else {
this.$refs.scroll.style.transform = `translate3d(0,${-this.refs.descHeight + this.floatHeight}px,0)`
this.indicatorFixed = this.floatShowName = this.floatFixed = this.isScroll = true
this.moveYDistance = -this.refs.descHeight + this.floatHeight
this.moveYDistance = pageMoveDistance
}
}
this.indicatorFixed = this.floatShowName = this.floatFixed = this.isScroll = false
this.changeIndex(this.contentIndex, this.contentIndex)
} else {
//
this.$refs.scroll.style.transition = 'all .3s'
let offsetTop = this.refs.descHeight - this.floatHeight
if (this.refs.defaultVideoSlideRowListHeight > this.refs.videoSlideRowListHeight) {
let endTransformY = Math.abs(offsetTop) - (this.refs.defaultVideoSlideRowListHeight - this.refs.videoSlideRowListHeight)
this.$refs.scroll.style.transform = `translate3d(0,${-endTransformY}px,0)`
// this.floatShowName = this.floatFixed = true
this.floatFixed = Math.abs(endTransformY) > 100
this.floatShowName = Math.abs(endTransformY) > 150
this.moveYDistance = -endTransformY
} else {
this.$refs.scroll.style.transform = `translate3d(0,${-this.refs.descHeight + this.floatHeight}px,0)`
this.indicatorFixed = this.floatShowName = this.floatFixed = this.isScroll = true
this.moveYDistance = -this.refs.descHeight + this.floatHeight
}
// this.$refs.scroll.style.transition = 'all .3s'
// if (this.refs.defaultVideoSlideRowListHeight > this.refs.videoSlideRowListHeight) {
// this.$refs.scroll.style.transform = `translate3d(0,0,0)`
// // this.floatShowName = this.floatFixed = true
// this.floatFixed = Math.abs(endTransformY) > 100
// this.floatShowName = Math.abs(endTransformY) > 150
// this.moveYDistance = 0
// } else {
// this.$refs.scroll.style.transform = `translate3d(0,${-this.refs.descHeight + this.floatHeight}px,0)`
// this.indicatorFixed = this.floatShowName = this.floatFixed = this.isScroll = true
// this.moveYDistance = -this.refs.descHeight + this.floatHeight
this.moveYDistance = pageMoveDistance
// }
}
}
} else {
this.isScroll = true
}
},
getTransform(el) {

Loading…
Cancel
Save