From 68e47fa31271db5bd7d189fc160870f1a3bae311 Mon Sep 17 00:00:00 2001 From: kitian616 Date: Sun, 16 Dec 2018 21:21:12 +0800 Subject: [PATCH] feat: gallery supports pan-to-move --- _includes/scripts/lib/gallery.js | 130 +++++++++++++++++++------------ 1 file changed, 82 insertions(+), 48 deletions(-) diff --git a/_includes/scripts/lib/gallery.js b/_includes/scripts/lib/gallery.js index d1c502e3412..1793f040d18 100644 --- a/_includes/scripts/lib/gallery.js +++ b/_includes/scripts/lib/gallery.js @@ -17,28 +17,25 @@ this.$swiper = null; this.$swiperWrapper = null; this.$activeItem = null; - this.swiper = null; this.$items = []; - this.items = items; - this.disabled = false; this.contentWidth = 0; this.contentHeight = 0; - this.PreRect = null; - this.rect = null; - this.preVector = null; - this.vector = null; + this.swiper = null; + this.items = items; + this.disabled = false; + this.curIndex = 0; + this.touchCenter = null; + this.lastTouchCenter = null; + this.zoomRect = null; + this.lastZoomRect = null; + this.lastTranslate = null; + this.translate = null; + this.lastZoom = 1; this.preZoom = 1; this.zoom = 1; } - Gallery.prototype._handleChangeEnd = function(index, $dom, preIndex, $preDom) { - this.PreRect = null; this.rect = null; - this.preVector = null; this.vector = { x: 0, y:0 }; - this.preZoom = 1; this.zoom = 1; - this.$activeItem = $dom.find('.gallery-item__content'); - setState($preDom.find('.gallery-item__content'), this.zoom, this.vector); - }; Gallery.prototype.init = function() { - var i, item, items = this.items, size, self = this; + var i, item, items = this.items, size, self = this, touchstartFingerCount = 0; this.$root.append(template); this.$swiper = this.$root.find('.gallery__swiper'); this.$swiperWrapper = this.$root.find('.swiper__wrapper'); @@ -46,7 +43,7 @@ this.contentHeight = this.$swiperWrapper && this.$swiperWrapper.height(); for (i = 0; i < items.length; i++) { item = items[i]; - size = this.calculateImageSize(item.w, item.h); + size = this._calculateImageSize(item.w, item.h); this.$items.push($( '
' + '