Skip to content

Commit d204b30

Browse files
committed
更新至Vue2.0
1 parent 9c4f8ad commit d204b30

File tree

6 files changed

+371
-58
lines changed

6 files changed

+371
-58
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# slider
2-
auto banner for more function
2+
auto banner for more function for Vue2.x
33

44
##demo
55

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"test": ""
1111
},
1212
"dependencies": {
13-
"vue": "^1.0.21",
13+
"vue": "^2.0.0",
1414
"babel-runtime": "^6.0.0"
1515
},
1616
"devDependencies": {
@@ -37,7 +37,7 @@
3737
"url-loader": "^0.5.7",
3838
"vue-hot-reload-api": "^1.2.0",
3939
"vue-html-loader": "^1.0.0",
40-
"vue-loader": "^8.3.0",
40+
"vue-loader": "^9.0.0",
4141
"vue-style-loader": "^1.0.0",
4242
"webpack": "^1.12.2",
4343
"webpack-dev-middleware": "^1.4.0",

src/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@slide-revert-end="onSlideRevertEnd"
1212
@slider-move="onSliderMove">
1313

14-
<div v-for="slide in slides" track-by="$index">
14+
<div v-for="(slide,index) in slides" :key="index">
1515
<a :href="slide.value">
1616
<img width="350" height="180" :src="slide.image" />
1717
</a>

src/components/vue-slider.vue

+54-52
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
<template>
22
<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>
2121
</template>
2222
<script type="text/babel">
2323
const VERTICAL = 'vertical';
@@ -73,14 +73,16 @@
7373
},
7474
watch:{
7575
slides:function(){
76-
this.slideEls = this.$els.swiperWrap.children;
76+
this.slideEls = this.$refs['swiper-wrap'].children;
7777
}
7878
},
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+
})
8486
},
8587
methods: {
8688
@@ -129,8 +131,8 @@
129131
//偏移的大小
130132
this[translateName] = -[].reduce.call(this.slideEls, function (total, el, i) {
131133
//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);
134136
this._onTransitionStart();
135137
this.autoBegin();
136138
},
@@ -238,36 +240,36 @@
238240

239241
<style lang="less">
240242
.swiper {
241-
position: relative;
242-
overflow: hidden;
243+
position: relative;
244+
overflow: hidden;
243245
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;
249251
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+
}
256258
}
257259
258260
&.horizontal .swiper-wrap {
259261
flex-direction: row;
260-
}
262+
}
261263
262-
&.vertical .swiper-wrap {
264+
&.vertical .swiper-wrap {
263265
flex-direction: column;
264-
}
266+
}
265267
266-
&.dragging .swiper-wrap {
268+
&.dragging .swiper-wrap {
267269
transition: none;
268-
}
270+
}
269271
270-
.swiper-pagination {
272+
.swiper-pagination {
271273
position: absolute;
272274
273275
.swiper-pagination-bullet {
@@ -277,35 +279,35 @@
277279
background-color: #000000;
278280
opacity: .2;
279281
cursor:pointer
280-
}
282+
}
281283
282-
.swiper-pagination-bullet.active {
284+
.swiper-pagination-bullet.active {
283285
background: #007aff;
284286
opacity: 1;
285-
}
286287
}
288+
}
287289
288-
&.vertical .swiper-pagination {
290+
&.vertical .swiper-pagination {
289291
right: 10px;
290292
top: 50%;
291293
transform: translate3d(0, -50%, 0);
292294
293295
.swiper-pagination-bullet {
294296
display: block;
295297
margin: 3px 0;
296-
}
297298
}
299+
}
298300
299-
&.horizontal .swiper-pagination {
301+
&.horizontal .swiper-pagination {
300302
bottom: 10px;
301303
width: 100%;
302304
text-align: center;
303305
304306
.swiper-pagination-bullet {
305307
display: inline-block;
306308
margin: 0 3px;
307-
}
308309
}
309310
}
311+
}
310312
311313
</style>

0 commit comments

Comments
 (0)