From bc925301b50a56d4190f11254f0259a10fc019b2 Mon Sep 17 00:00:00 2001 From: Jason Wan Date: Wed, 19 Feb 2014 13:50:37 -0800 Subject: [PATCH] Modification to calculation of child width in order to support variable width child elements --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 941e2a4..b390219 100644 --- a/index.js +++ b/index.js @@ -107,8 +107,12 @@ Swipe.prototype.refresh = function(){ } this.visible = visible; - this.childWidth = this.el.getBoundingClientRect().width; - this.width = Math.ceil(this.childWidth * visible); + this.childWidth = [0]; + this.width = 0; + for(var i = 0, size = this.children().all.length; i < size; i++) { + this.width += this.children().all[i].clientWidth; + this.childWidth.push(this.width); + } this.child.style.width = this.width + 'px'; this.child.style.height = this.height + 'px'; this.show(this.currentVisible, 0, { silent: true }); @@ -394,7 +398,7 @@ Swipe.prototype.show = function(i, ms, options){ this.currentEl = children.visible[i]; this.current = indexOf(children.all, this.currentEl); this.transitionDuration(ms); - this.translate(this.childWidth * i); + this.translate(this.childWidth[i]); if (!options.silent) { this.emit('showing', this.current, this.currentEl);