| xqd
@@ -1,15 +1,16 @@
|
|
|
<template>
|
|
|
- <view style="width:100%;overflow:hidden">
|
|
|
- <view class="scroll-hotel"
|
|
|
- @touchstart="touchStart"
|
|
|
- @touchmove="touchMove"
|
|
|
- @touchend="touchEnd"
|
|
|
+ <scroll-view id="scroll-container" class="scroll-hotel"
|
|
|
@touchcancel="touchEnd"
|
|
|
- :style="{transform: scrollX,width: totalWidth+'rpx'}"
|
|
|
+ @touchend="touchEnd"
|
|
|
+ @scroll="scroll"
|
|
|
+ :scroll-left="scrolls.scrollX"
|
|
|
+ :scroll-with-animation="true"
|
|
|
+ :scroll-x="true"
|
|
|
+ :scroll-into-view="index"
|
|
|
>
|
|
|
<view style="width: 16rpx;display: inline-block;"></view>
|
|
|
- <view class="address-detail" v-for="(item,index) in hotelList" :key="index">
|
|
|
- <view :class="{mark:true, on:index == -activeIndex}" style="overflow: hidden;">
|
|
|
+ <view :id="`i${index}`" class="address-detail" v-for="(item,index) in hotelList" :key="index">
|
|
|
+ <view :class="{mark:true, on:index == scrolls.activeIndex}" style="overflow: hidden;">
|
|
|
<image :src="item.bg_img" mode="aspectFill"></image>
|
|
|
</view>
|
|
|
<view class="inner">
|
| xqd
@@ -38,8 +39,7 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
<view style="width: 16rpx;display: inline-block;"></view>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
+ </scroll-view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
| xqd
@@ -52,23 +52,26 @@
|
|
|
},
|
|
|
speed: {
|
|
|
type: Number,
|
|
|
- default:4
|
|
|
+ default:2
|
|
|
}
|
|
|
},
|
|
|
data(){
|
|
|
return {
|
|
|
+ target:"",
|
|
|
scrolls:{
|
|
|
+ r: 0,
|
|
|
compensate: 0,
|
|
|
screenWidth: 750,
|
|
|
- scrollX: 0,
|
|
|
+ scrollX: -1,
|
|
|
itemWidth: 512,
|
|
|
isAppend: false,
|
|
|
+ activeIndex:0,
|
|
|
},
|
|
|
move:{
|
|
|
oldX: 0,
|
|
|
direct: 0,
|
|
|
isMove: false
|
|
|
- }
|
|
|
+ },
|
|
|
}
|
|
|
},
|
|
|
computed:{
|
| xqd
@@ -89,6 +92,7 @@
|
|
|
uni.getSystemInfo({
|
|
|
success: (res)=>{
|
|
|
const r = res.screenWidth / 750;
|
|
|
+ this.scrolls.r = r
|
|
|
const rs = Math.ceil(r * 10)/10;
|
|
|
this.scrolls.compensate = Math.abs(Math.floor((r - rs) * 100)/2);
|
|
|
}
|
| xqd
@@ -96,52 +100,39 @@
|
|
|
},
|
|
|
methods:{
|
|
|
touchStart(e){
|
|
|
- this.move.oldX = e.touches[0].clientX;
|
|
|
+ // this.move.oldX = e.touches[0].clientX;
|
|
|
},
|
|
|
- touchMove(e){
|
|
|
- if(this.move.isMove) return;
|
|
|
- const newX = e.touches[0].clientX
|
|
|
- const baseSpeed = Math.abs(newX - this.move.oldX);
|
|
|
- // if(baseSpeed<2) return;
|
|
|
-
|
|
|
- this.move.direct = newX > this.move.oldX ? 1 : -1;
|
|
|
- this.move.oldX = newX;
|
|
|
- const newScrollX = this.scrolls.scrollX + this.speed*baseSpeed*this.move.direct;
|
|
|
- if(newScrollX > 20){
|
|
|
- this.scrolls.scrollX = 20;
|
|
|
- }else if(this.hotelList.length<=1 && newScrollX < this.maxRight - 20 ){
|
|
|
- this.scrolls.scrollX = this.maxRight - 20;
|
|
|
- }else if(this.hotelList.length>1 && newScrollX < this.maxRight - 40 + (this.scrolls.screenWidth - this.scrolls.itemWidth-16)){
|
|
|
- this.scrolls.scrollX = this.maxRight - 40 + (this.scrolls.screenWidth - this.scrolls.itemWidth-16);
|
|
|
- }else{
|
|
|
- this.scrolls.scrollX = newScrollX
|
|
|
- }
|
|
|
- this.move.isMove = true;
|
|
|
- setTimeout(()=>{
|
|
|
- this.move.isMove = false;
|
|
|
- }, 50)
|
|
|
+ scroll(e){
|
|
|
+ const newScrollX = e.detail.scrollLeft / this.scrolls.r;
|
|
|
+ const newIndex = Math.floor(((newScrollX + 750 + 50) / this.scrolls.itemWidth) - 1)
|
|
|
+ if(this.scrolls.activeIndex == newIndex) return;
|
|
|
+ this.scrolls.activeIndex = newIndex
|
|
|
+ this.$emit('updateIndex', this.scrolls.activeIndex);
|
|
|
},
|
|
|
touchEnd(isUpdate){
|
|
|
- if(this.scrolls.scrollX > 0){
|
|
|
- this.scrolls.scrollX = 0;
|
|
|
- }else if(this.hotelList.length<=1 && this.scrolls.scrollX < this.maxRight){
|
|
|
- this.scrolls.scrollX = this.maxRight;
|
|
|
- }else if(this.hotelList.length>1 && this.scrolls.scrollX < this.maxRight + (this.scrolls.screenWidth - this.scrolls.itemWidth-16)){
|
|
|
- this.scrolls.scrollX = this.maxRight + (this.scrolls.screenWidth - this.scrolls.itemWidth-16)
|
|
|
- }else{
|
|
|
- if(this.activeIndex == 0){
|
|
|
- this.scrolls.scrollX = 0;
|
|
|
- }else if(this.activeIndex == -(this.hotelList.length - 1)){
|
|
|
- this.scrolls.scrollX = this.maxRight + (this.scrolls.screenWidth - this.scrolls.itemWidth -16)
|
|
|
- }else{
|
|
|
- this.scrolls.scrollX = this.activeIndex * this.scrolls.itemWidth + (this.scrolls.screenWidth - this.scrolls.itemWidth)/2 - this.activeIndex*this.scrolls.compensate;
|
|
|
- }
|
|
|
- }
|
|
|
- isUpdate && this.$emit('updateIndex', -this.activeIndex);
|
|
|
+ // this.scrolls.scrollX =( this.scrolls.activeIndex * this.scrolls.itemWidth - (750 - this.scrolls.itemWidth) / 2 ) + 'rpx'
|
|
|
+ // if(current > 0){
|
|
|
+ // this.scrolls.scrollX = 0;
|
|
|
+ // }else if(this.hotelList.length<=1 && current < this.maxRight){
|
|
|
+ // this.scrolls.scrollX = this.maxRight;
|
|
|
+ // }else if(this.hotelList.length>1 && current < this.maxRight + (this.scrolls.screenWidth - this.scrolls.itemWidth-16)){
|
|
|
+ // this.scrolls.scrollX = this.maxRight + (this.scrolls.screenWidth - this.scrolls.itemWidth-16)
|
|
|
+ // }else{
|
|
|
+ // if(this.activeIndex == 0){
|
|
|
+ // this.scrolls.scrollX = 0;
|
|
|
+ // }else if(this.activeIndex == -(this.hotelList.length - 1)){
|
|
|
+ // this.scrolls.scrollX = this.maxRight + (this.scrolls.screenWidth - this.scrolls.itemWidth -16)
|
|
|
+ // }else{
|
|
|
+ // this.scrolls.scrollX = this.activeIndex * this.scrolls.itemWidth + (this.scrolls.screenWidth - this.scrolls.itemWidth)/2 - this.activeIndex*this.scrolls.compensate;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // console.log(this.scrolls.scrollX)
|
|
|
+ // isUpdate && this.$emit('updateIndex', -this.activeIndex);
|
|
|
+
|
|
|
},
|
|
|
setActiveIndex(index){
|
|
|
- this.scrolls.scrollX = -index * this.scrolls.itemWidth;
|
|
|
- this.touchEnd(false);
|
|
|
+ this.scrolls.scrollX = ( index * this.scrolls.itemWidth - (750 - this.scrolls.itemWidth) / 2 ) + 'rpx'
|
|
|
+ // this.touchEnd(false);
|
|
|
},
|
|
|
goBook(){
|
|
|
|
| xqd
@@ -152,8 +143,9 @@
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
.scroll-hotel{
|
|
|
+ width: 100%;
|
|
|
height:318rpx;white-space: nowrap;
|
|
|
- transition: transform 100ms linear;
|
|
|
+ transition: transform 5ms linear;
|
|
|
|
|
|
.address-detail {
|
|
|
display: inline-block;
|