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>
|
||||
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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user