Skip to content

Commit

Permalink
add loop option
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan Claret committed Jun 29, 2015
1 parent 039f6e3 commit dc15fd2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ Available options
```javascript
$(document).ready(function(){
$('.jc-slider').jcSlider({
animationIn: "bounceInRight",
animationOut: "bounceOutLeft",
stopOnHover: false // true by default
animationIn : "bounceInRight",
animationOut : "bounceOutLeft",
stopOnHover : false, // true by default
loop : false // true by default
});
});
```
Expand Down
16 changes: 11 additions & 5 deletions jquery.jcslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,18 @@
// get settings
var settings = $.extend({
// default settings
animationIn: 'bounceInRight',
animationOut: 'bounceOutLeft',
stopOnHover: true
animationIn : 'bounceInRight',
animationOut : 'bounceOutLeft',
stopOnHover : true,
loop : false
}, options );

var animateOut = 'animated ' + settings.animationOut;
var animateIn = 'animated ' + settings.animationIn;
var animationItem = $this.find('.jc-animation');
var animationItemsLength = animationItem.length;
var animationCurrentItem = 0;
var jcSliderInterval = '';
var jcSliderInterval = null;


// Detect when animations (keyframes) end
Expand Down Expand Up @@ -80,6 +81,11 @@
var jcSliderAnimation = function() {

jcSliderInterval = setInterval(function() {

// stop animation if loop is false and we are on the last image
if (settings.loop === false && animationCurrentItem == (animationItemsLength -2)) {
clearInterval(jcSliderInterval);
}

animationItem.eq(animationCurrentItem)
.removeClass(animateIn) // reset enter animation
Expand Down Expand Up @@ -119,7 +125,7 @@
// Stop the animation on hover
$this.hover(
function() {
clearInterval(jcSliderInterval);
clearInterval(jcSliderInterval);
},
function(){
jcSliderAnimation();
Expand Down
2 changes: 1 addition & 1 deletion jquery.jcslider.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dc15fd2

Please sign in to comment.