Permalink
Browse files

add .refresh()

  • Loading branch information...
1 parent 302cf77 commit 7b13c3a95e9e72f909e41a7911f989479dd1f6ac @tj tj committed Feb 15, 2013
Showing with 18 additions and 5 deletions.
  1. +5 −0 Readme.md
  2. +13 −5 index.js
View
@@ -23,6 +23,11 @@
Set the cycle interval, defaults to 5000ms.
+### .refresh()
+
+ This method should be invoked when the swipe element
+ has been resized, or an item has been added or removed.
+
### .play()
Play through all items using the cycle interval.
View
@@ -24,11 +24,7 @@ function Swipe(el) {
if (!el) throw new TypeError('Swipe() requires an element');
this.el = el;
this.child = el.children[0];
- this.total = this.child.children.length;
- this.childWidth = el.getBoundingClientRect().width;
- this.width = this.childWidth * this.total | 0;
- this.child.style.width = this.width + 'px';
- this.child.style.height = this.height + 'px';
+ this.refresh();
this.interval(5000);
this.duration(300);
this.show(0, 0);
@@ -42,6 +38,18 @@ function Swipe(el) {
Emitter(Swipe.prototype);
/**
+ * Refresh sizing data.
+ *
+ * @api public
+ */
+
+Swipe.prototype.refresh = function(){
+ this.total = this.child.children.length;
+ this.childWidth = el.getBoundingClientRect().width;
+ this.width = this.childWidth * this.total | 0;
+ this.child.style.width = this.width + 'px';
+ this.child.style.height = this.height + 'px';
+};
/**
* Bind event handlers.

0 comments on commit 7b13c3a

Please sign in to comment.