|
1 | 1 | <template>
|
2 | 2 | <div class="swiper"
|
3 |
| - :class="[direction, {'dragging': dragging}]" |
4 |
| - @touchstart="_onTouchStart" |
5 |
| - @wheel="_onWheel"> |
6 |
| - <div class="swiper-wrap" |
7 |
| - v-el:swiper-wrap |
8 |
| - :style="{'transform' : 'translate3d(' + translateX + 'px,' + translateY + 'px, 0)'}" |
9 |
| - @transitionend="_onTransitionEnd"> |
10 |
| - <slot></slot> |
11 |
| - </div> |
12 |
| - <div class="swiper-pagination" |
13 |
| - v-show="paginationVisible"> |
14 |
| - <span class="swiper-pagination-bullet" |
15 |
| - :class="{'active': $index+1===currentPage}" |
16 |
| - v-for="slide in slides" |
17 |
| - track-by="$index" |
18 |
| - @click="setPage($index+1)"></span> |
19 |
| - </div> |
20 |
| - </div> |
| 3 | + :class="[direction, {'dragging': dragging}]" |
| 4 | + @touchstart="_onTouchStart" |
| 5 | + @wheel="_onWheel"> |
| 6 | + <div class="swiper-wrap" |
| 7 | + ref="swiper-wrap" |
| 8 | + :style="{'transform' : 'translate3d(' + translateX + 'px,' + translateY + 'px, 0)'}" |
| 9 | + @transitionend="_onTransitionEnd"> |
| 10 | + <slot></slot> |
| 11 | +</div> |
| 12 | +<div class="swiper-pagination" |
| 13 | +v-show="paginationVisible"> |
| 14 | +<span class="swiper-pagination-bullet" |
| 15 | +:class="{'active': index+1===currentPage}" |
| 16 | +v-for="(slide,index) in slides" |
| 17 | +:key="index" |
| 18 | +@click="setPage(index+1)"></span> |
| 19 | +</div> |
| 20 | +</div> |
21 | 21 | </template>
|
22 | 22 | <script type="text/babel">
|
23 | 23 | const VERTICAL = 'vertical';
|
|
73 | 73 | },
|
74 | 74 | watch:{
|
75 | 75 | slides:function(){
|
76 |
| - this.slideEls = this.$els.swiperWrap.children; |
| 76 | + this.slideEls = this.$refs['swiper-wrap'].children; |
77 | 77 | }
|
78 | 78 | },
|
79 |
| - ready() { |
80 |
| - this._onTouchMove = this._onTouchMove.bind(this); |
81 |
| - this._onTouchEnd = this._onTouchEnd.bind(this); |
82 |
| - this.slideEls = this.$els.swiperWrap.children; |
83 |
| - this.autoBegin(); |
| 79 | + mounted(){ |
| 80 | + this.$nextTick(function () { |
| 81 | + this._onTouchMove = this._onTouchMove.bind(this); |
| 82 | + this._onTouchEnd = this._onTouchEnd.bind(this); |
| 83 | + this.slideEls = this.$refs['swiper-wrap'].children; |
| 84 | + this.autoBegin(); |
| 85 | + }) |
84 | 86 | },
|
85 | 87 | methods: {
|
86 | 88 |
|
|
129 | 131 | //偏移的大小
|
130 | 132 | this[translateName] = -[].reduce.call(this.slideEls, function (total, el, i) {
|
131 | 133 | //previousValue,currentValue,currentIndex
|
132 |
| - return i > page - 2 ? total : total + el[propName]; |
133 |
| - }, 0); |
| 134 | + return i > page - 2 ? total : total + el[propName]; |
| 135 | + }, 0); |
134 | 136 | this._onTransitionStart();
|
135 | 137 | this.autoBegin();
|
136 | 138 | },
|
|
238 | 240 |
|
239 | 241 | <style lang="less">
|
240 | 242 | .swiper {
|
241 |
| - position: relative; |
242 |
| - overflow: hidden; |
| 243 | + position: relative; |
| 244 | + overflow: hidden; |
243 | 245 |
|
244 |
| - .swiper-wrap { |
245 |
| - display: flex; |
246 |
| - width: 100%; |
247 |
| - height: 100%; |
248 |
| - transition: all 0.5s ease; |
| 246 | + .swiper-wrap { |
| 247 | + display: flex; |
| 248 | + width: 100%; |
| 249 | + height: 100%; |
| 250 | + transition: all 0.4s ease; |
249 | 251 |
|
250 |
| - > div { |
251 |
| - overflow: hidden; |
252 |
| - flex-shrink: 0; |
253 |
| - width: 100%; |
254 |
| - height: 100%; |
255 |
| - } |
| 252 | + > div { |
| 253 | + overflow: hidden; |
| 254 | + flex-shrink: 0; |
| 255 | + width: 100%; |
| 256 | + height: 100%; |
| 257 | + } |
256 | 258 | }
|
257 | 259 |
|
258 | 260 | &.horizontal .swiper-wrap {
|
259 | 261 | flex-direction: row;
|
260 |
| - } |
| 262 | +} |
261 | 263 |
|
262 |
| - &.vertical .swiper-wrap { |
| 264 | +&.vertical .swiper-wrap { |
263 | 265 | flex-direction: column;
|
264 |
| - } |
| 266 | +} |
265 | 267 |
|
266 |
| - &.dragging .swiper-wrap { |
| 268 | +&.dragging .swiper-wrap { |
267 | 269 | transition: none;
|
268 |
| - } |
| 270 | +} |
269 | 271 |
|
270 |
| - .swiper-pagination { |
| 272 | +.swiper-pagination { |
271 | 273 | position: absolute;
|
272 | 274 |
|
273 | 275 | .swiper-pagination-bullet {
|
|
277 | 279 | background-color: #000000;
|
278 | 280 | opacity: .2;
|
279 | 281 | cursor:pointer
|
280 |
| - } |
| 282 | + } |
281 | 283 |
|
282 |
| - .swiper-pagination-bullet.active { |
| 284 | + .swiper-pagination-bullet.active { |
283 | 285 | background: #007aff;
|
284 | 286 | opacity: 1;
|
285 |
| - } |
286 | 287 | }
|
| 288 | +} |
287 | 289 |
|
288 |
| - &.vertical .swiper-pagination { |
| 290 | +&.vertical .swiper-pagination { |
289 | 291 | right: 10px;
|
290 | 292 | top: 50%;
|
291 | 293 | transform: translate3d(0, -50%, 0);
|
292 | 294 |
|
293 | 295 | .swiper-pagination-bullet {
|
294 | 296 | display: block;
|
295 | 297 | margin: 3px 0;
|
296 |
| - } |
297 | 298 | }
|
| 299 | +} |
298 | 300 |
|
299 |
| - &.horizontal .swiper-pagination { |
| 301 | +&.horizontal .swiper-pagination { |
300 | 302 | bottom: 10px;
|
301 | 303 | width: 100%;
|
302 | 304 | text-align: center;
|
303 | 305 |
|
304 | 306 | .swiper-pagination-bullet {
|
305 | 307 | display: inline-block;
|
306 | 308 | margin: 0 3px;
|
307 |
| - } |
308 | 309 | }
|
309 | 310 | }
|
| 311 | +} |
310 | 312 |
|
311 | 313 | </style>
|
0 commit comments