[Improvement] Swipe: window resize (#1413)

This commit is contained in:
neverland 2018-07-05 20:15:46 +08:00 committed by GitHub
parent 864b386c43
commit 0149dc0976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,7 @@
<script>
import create from '../utils/create';
import Touch from '../mixins/touch';
import { on, off } from '../utils/event';
export default create({
name: 'swipe',
@ -72,10 +73,18 @@ export default create({
mounted() {
this.initialize();
if (!this.$isServer) {
on(window, 'resize', this.onResize, true);
}
},
destroyed() {
this.clear();
if (!this.$isServer) {
off(window, 'resize', this.onResize, true);
}
},
watch: {
@ -128,7 +137,7 @@ export default create({
methods: {
// initialize swipe position
initialize() {
initialize(active = this.initialSwipe) {
clearTimeout(this.timer);
if (this.$el) {
const rect = this.$el.getBoundingClientRect();
@ -136,7 +145,7 @@ export default create({
this.height = rect.height;
}
this.swiping = true;
this.active = this.initialSwipe;
this.active = active;
this.offset = this.count > 1 ? -this.size * this.active : 0;
this.swipes.forEach(swipe => {
swipe.offset = 0;
@ -144,6 +153,10 @@ export default create({
this.autoPlay();
},
onResize() {
this.initialize(this.activeIndicator);
},
onTouchStart(event) {
if (!this.touchable) return;