mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[Improvement] Swipe: window resize (#1413)
This commit is contained in:
parent
864b386c43
commit
0149dc0976
@ -26,6 +26,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import create from '../utils/create';
|
import create from '../utils/create';
|
||||||
import Touch from '../mixins/touch';
|
import Touch from '../mixins/touch';
|
||||||
|
import { on, off } from '../utils/event';
|
||||||
|
|
||||||
export default create({
|
export default create({
|
||||||
name: 'swipe',
|
name: 'swipe',
|
||||||
@ -72,10 +73,18 @@ export default create({
|
|||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.initialize();
|
this.initialize();
|
||||||
|
|
||||||
|
if (!this.$isServer) {
|
||||||
|
on(window, 'resize', this.onResize, true);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
destroyed() {
|
destroyed() {
|
||||||
this.clear();
|
this.clear();
|
||||||
|
|
||||||
|
if (!this.$isServer) {
|
||||||
|
off(window, 'resize', this.onResize, true);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
@ -128,7 +137,7 @@ export default create({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
// initialize swipe position
|
// initialize swipe position
|
||||||
initialize() {
|
initialize(active = this.initialSwipe) {
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
if (this.$el) {
|
if (this.$el) {
|
||||||
const rect = this.$el.getBoundingClientRect();
|
const rect = this.$el.getBoundingClientRect();
|
||||||
@ -136,7 +145,7 @@ export default create({
|
|||||||
this.height = rect.height;
|
this.height = rect.height;
|
||||||
}
|
}
|
||||||
this.swiping = true;
|
this.swiping = true;
|
||||||
this.active = this.initialSwipe;
|
this.active = active;
|
||||||
this.offset = this.count > 1 ? -this.size * this.active : 0;
|
this.offset = this.count > 1 ? -this.size * this.active : 0;
|
||||||
this.swipes.forEach(swipe => {
|
this.swipes.forEach(swipe => {
|
||||||
swipe.offset = 0;
|
swipe.offset = 0;
|
||||||
@ -144,6 +153,10 @@ export default create({
|
|||||||
this.autoPlay();
|
this.autoPlay();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onResize() {
|
||||||
|
this.initialize(this.activeIndicator);
|
||||||
|
},
|
||||||
|
|
||||||
onTouchStart(event) {
|
onTouchStart(event) {
|
||||||
if (!this.touchable) return;
|
if (!this.touchable) return;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user