Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@

Is on the last visisble item.

### .prev()
### .prev(cycle)

Show the previous item if present, or do nothing.
Show the previous item.
By default, do nothing if showing the first item.
If `cycle` is true and we are on the first item, display the last item.

### .next()
### .next(cycle)

Show the next item if present, or do nothing.
Show the next item.
By default, do nothing if showing the last item.
If `cycle` is true and we are on the last item, display the first item.

### .show(i, [ms], [options])

Expand Down
2 changes: 2 additions & 0 deletions examples/grumpy.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@

<button onclick="cats.prev()">prev</button>
<button onclick="cats.next()">next</button>
<button onclick="cats.prev(true)">prev(true)</button>
<button onclick="cats.next(true)">next(true)</button>
<button onclick="cats.play()">play</button>
<button onclick="cats.stop()">stop</button>
<button onclick="remove(0)">remove(0)</button>
Expand Down
17 changes: 9 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,7 @@ Swipe.prototype.stop = function(){
*/

Swipe.prototype.cycle = function(){
if (this.isLast()) {
this.currentVisible = -1;
this.next();
} else {
this.next();
}
return this.next(true);
};

/**
Expand Down Expand Up @@ -353,7 +348,10 @@ Swipe.prototype.isLast = function(){
* @api public
*/

Swipe.prototype.prev = function(){
Swipe.prototype.prev = function(cycle){
if (cycle && this.isFirst()) {
this.currentVisible = this.visible;
}
this.show(this.currentVisible - 1);
return this;
};
Expand All @@ -365,7 +363,10 @@ Swipe.prototype.prev = function(){
* @api public
*/

Swipe.prototype.next = function(){
Swipe.prototype.next = function(cycle){
if (cycle && this.isLast()) {
this.currentVisible = -1;
}
this.show(this.currentVisible + 1);
return this;
};
Expand Down