Showing
2 changed files
with
154 additions
and
2 deletions
1 | <template> | 1 | <template> |
2 | - <resource class="no-padding-right"> | ||
3 | - <ul class="resource-tf-goods"> | 2 | + <resource class="no-padding-right product-list-more"> |
3 | + <ul class="resource-tf-goods" | ||
4 | + @touchstart="touchStart" | ||
5 | + @touchmove="touchMove" | ||
6 | + @touchend="touchEnd" | ||
7 | + ref="goodsList" | ||
8 | + :style="moreSlider" | ||
9 | + :class="{'less-slider': value.data.list.length <= 3}" | ||
10 | + > | ||
4 | <li class="product-item" v-for="(item, pi) in value.data.list" :key="pi"> | 11 | <li class="product-item" v-for="(item, pi) in value.data.list" :key="pi"> |
5 | <product-link :value="item" class="link" :yas="value" :yas-f="index" :yas-i="pi"></product-link> | 12 | <product-link :value="item" class="link" :yas="value" :yas-f="index" :yas-i="pi"></product-link> |
6 | <img-format :lazy="lazy" :src="item.default_images" :w="188" :h="250"></img-format> | 13 | <img-format :lazy="lazy" :src="item.default_images" :w="188" :h="250"></img-format> |
@@ -10,6 +17,7 @@ | @@ -10,6 +17,7 @@ | ||
10 | </div> | 17 | </div> |
11 | </li> | 18 | </li> |
12 | </ul> | 19 | </ul> |
20 | + <div class="more" :class="{'show-more': value.data.list.length <= 3}" :style="moreMove" ref="more" v-show="value.data.url" @click="moreAction"></div> | ||
13 | </resource> | 21 | </resource> |
14 | </template> | 22 | </template> |
15 | 23 | ||
@@ -18,6 +26,16 @@ import Resource from './resource'; | @@ -18,6 +26,16 @@ import Resource from './resource'; | ||
18 | 26 | ||
19 | export default { | 27 | export default { |
20 | name: 'ResourceTfGoodsList', | 28 | name: 'ResourceTfGoodsList', |
29 | + data() { | ||
30 | + return { | ||
31 | + startX: 0, | ||
32 | + endX: 0, | ||
33 | + moveX: 0, | ||
34 | + disX: 0, | ||
35 | + moreSlider: '', | ||
36 | + moreMove: '' | ||
37 | + }; | ||
38 | + }, | ||
21 | props: { | 39 | props: { |
22 | value: Object, | 40 | value: Object, |
23 | lazy: Boolean, | 41 | lazy: Boolean, |
@@ -25,6 +43,90 @@ export default { | @@ -25,6 +43,90 @@ export default { | ||
25 | }, | 43 | }, |
26 | computed: { | 44 | computed: { |
27 | }, | 45 | }, |
46 | + methods: { | ||
47 | + touchStart(ev) { | ||
48 | + ev = ev || event; | ||
49 | + | ||
50 | + // tounches类数组,等于1时表示此时有只有一只手指在触摸屏幕 | ||
51 | + if (ev.touches.length === 1) { | ||
52 | + | ||
53 | + // 记录开始位置 | ||
54 | + this.startX = ev.touches[0].clientX; | ||
55 | + } | ||
56 | + }, | ||
57 | + touchMove(ev) { | ||
58 | + let wd = this.$refs.goodsList.scrollWidth - this.$refs.goodsList.offsetWidth; | ||
59 | + let moreWd = this.$refs.more.offsetWidth; | ||
60 | + let scrollLeft = this.$refs.goodsList.scrollLeft; | ||
61 | + | ||
62 | + if (this.value.data.list.length <= 3 || !this.value.data.url) { | ||
63 | + return; | ||
64 | + } | ||
65 | + | ||
66 | + if (ev.touches.length === 1 && scrollLeft >= wd) { | ||
67 | + | ||
68 | + // 滑动时距离浏览器左侧实时距离 | ||
69 | + this.moveX = ev.touches[0].clientX; | ||
70 | + | ||
71 | + // 起始位置减去 实时的滑动的距离,得到手指实时偏移距离 | ||
72 | + this.disX = this.startX - this.moveX; | ||
73 | + | ||
74 | + // 如果是向右滑动或者不滑动,不改变滑块的位置 | ||
75 | + if (this.disX < 0 || this.disX === 0) { | ||
76 | + this.moreSlider = 'transform:translateX(0px)'; | ||
77 | + this.moreMove = 'transform:translateX(' + moreWd + 'px)'; | ||
78 | + | ||
79 | + // 大于0,表示左滑了,此时滑块开始滑动 | ||
80 | + } else if (this.disX > 0) { | ||
81 | + | ||
82 | + // 具体滑动距离我取的是 手指偏移距离*5。 | ||
83 | + this.moreSlider = 'transform:translateX(-' + this.disX * 5 + 'px)'; | ||
84 | + this.moreMove = 'transform:translateX(' + moreWd - this.disX + 'px)'; | ||
85 | + | ||
86 | + // 最大也只能等于按钮宽度 | ||
87 | + if (this.disX * 5 >= moreWd) { | ||
88 | + this.moreSlider = 'transform:translateX(-' + moreWd + 'px)'; | ||
89 | + this.moreMove = 'transform:translateX(0px)'; | ||
90 | + } | ||
91 | + } | ||
92 | + } else { | ||
93 | + this.moreSlider = 'transform:translateX(0px)'; | ||
94 | + this.moreMove = 'transform:translateX(' + moreWd + 'px)'; | ||
95 | + } | ||
96 | + }, | ||
97 | + touchEnd(ev) { | ||
98 | + let wd = this.$refs.goodsList.scrollWidth - this.$refs.goodsList.offsetWidth; | ||
99 | + let moreWd = this.$refs.more.offsetWidth; | ||
100 | + let scrollLeft = this.$refs.goodsList.scrollLeft; | ||
101 | + | ||
102 | + if (this.value.data.list.length <= 3 || !this.value.data.url) { | ||
103 | + return; | ||
104 | + } | ||
105 | + | ||
106 | + if (ev.changedTouches.length === 1 && scrollLeft >= wd) { | ||
107 | + let endX = ev.changedTouches[0].clientX; | ||
108 | + | ||
109 | + this.disX = this.startX - endX; | ||
110 | + | ||
111 | + // 如果距离小于按钮一半,强行回到起点 | ||
112 | + if ((this.disX * 5) < (moreWd / 2)) { | ||
113 | + this.moreSlider = 'transform:translateX(0px)'; | ||
114 | + this.moreMove = 'transform:translateX(' + moreWd + 'px)'; | ||
115 | + } else { | ||
116 | + | ||
117 | + // 大于一半 滑动到最大值 | ||
118 | + location.href = this.value.data.url; | ||
119 | + } | ||
120 | + } | ||
121 | + }, | ||
122 | + moreAction() { | ||
123 | + if (this.value.data.list.length > 3) { | ||
124 | + return; | ||
125 | + } | ||
126 | + | ||
127 | + location.href = this.value.data.url; | ||
128 | + } | ||
129 | + }, | ||
28 | components: {Resource} | 130 | components: {Resource} |
29 | }; | 131 | }; |
30 | </script> | 132 | </script> |
@@ -36,6 +138,14 @@ export default { | @@ -36,6 +138,14 @@ export default { | ||
36 | -webkit-overflow-scrolling: touch; | 138 | -webkit-overflow-scrolling: touch; |
37 | white-space: nowrap; | 139 | white-space: nowrap; |
38 | overflow-y: hidden; | 140 | overflow-y: hidden; |
141 | + display: inline-block; | ||
142 | + transition: 0.5s; | ||
143 | + position: absolute; | ||
144 | + left: 0; | ||
145 | + right: 0; | ||
146 | + z-index: 200; | ||
147 | + background: #fff; | ||
148 | + padding-left: 20px; | ||
39 | 149 | ||
40 | li.product-item { | 150 | li.product-item { |
41 | position: relative; | 151 | position: relative; |
@@ -65,7 +175,11 @@ export default { | @@ -65,7 +175,11 @@ export default { | ||
65 | max-width: 188px; | 175 | max-width: 188px; |
66 | line-height: 28px; | 176 | line-height: 28px; |
67 | margin-top: 24px; | 177 | margin-top: 24px; |
178 | +<<<<<<< HEAD | ||
68 | font-family: "SanFranciscoText-Regular"; | 179 | font-family: "SanFranciscoText-Regular"; |
180 | +======= | ||
181 | + font-family: HelveticaNeue, Tahoma, Arial, HiraginoSansGB-W3, "PingFang SC", "Heiti SC"; | ||
182 | +>>>>>>> feature/leftScrollMore | ||
69 | 183 | ||
70 | &.price { | 184 | &.price { |
71 | font-size: 28px; | 185 | font-size: 28px; |
@@ -74,4 +188,42 @@ export default { | @@ -74,4 +188,42 @@ export default { | ||
74 | } | 188 | } |
75 | } | 189 | } |
76 | } | 190 | } |
191 | + | ||
192 | +.product-list-more { | ||
193 | + position: relative; | ||
194 | + height: 318px; | ||
195 | + | ||
196 | + .more { | ||
197 | + width: 113px; | ||
198 | + height: 250px; | ||
199 | + background: url("~statics/img/channel/more@2x.png") no-repeat; | ||
200 | + background-size: contain; | ||
201 | + position: absolute; | ||
202 | + right: 0; | ||
203 | + top: 20px; | ||
204 | + transform: translateX(113px); | ||
205 | + transition: 0.5s; | ||
206 | + } | ||
207 | + | ||
208 | + .show-more { | ||
209 | + width: 98px; | ||
210 | + position: relative; | ||
211 | + vertical-align: top; | ||
212 | + display: inline-block; | ||
213 | + top: 0; | ||
214 | + right: 0; | ||
215 | + transform: translateX(0); | ||
216 | + } | ||
217 | + | ||
218 | + .less-slider { | ||
219 | + width: auto; | ||
220 | + position: relative; | ||
221 | + right: auto; | ||
222 | + padding-left: 0; | ||
223 | + } | ||
224 | +} | ||
225 | + | ||
226 | +.scroller-box { | ||
227 | + overflow-x: hidden; | ||
228 | +} | ||
77 | </style> | 229 | </style> |
src/statics/img/channel/more@2x.png
0 → 100644

2.27 KB
-
Please register or login to post a comment