Skip to content

Commit

Permalink
Add option to center target slide
Browse files Browse the repository at this point in the history
This is a re-implementation of sachinchoolur#144
  • Loading branch information
dairiki committed Mar 30, 2016
1 parent 30e5025 commit 7d90ea7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ add the Following code to the <head> of your document.
nextHtml: '',
rtl:false,
centerSlide: false, // center the active slide
adaptiveHeight:false,
vertical:false,
Expand Down
13 changes: 10 additions & 3 deletions dist/js/lightslider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! lightslider - v1.1.5 - 2015-10-31
/*! lightslider - v1.1.5 - 2016-03-30
* https://github.com/sachinchoolur/lightslider
* Copyright (c) 2015 Sachin N; Licensed MIT */
* Copyright (c) 2016 Sachin N; Licensed MIT */
(function ($, undefined) {
'use strict';
var defaults = {
Expand All @@ -24,6 +24,7 @@
prevHtml: '',
nextHtml: '',
rtl: false,
centerSlide: false,
adaptiveHeight: false,
vertical: false,
verticalHeight: 500,
Expand Down Expand Up @@ -610,6 +611,12 @@
_sV += (parseInt($children.eq(i).width()) + settings.slideMargin);
}
}
if (settings.centerSlide) {
var extraWidth = elSize - $children.eq(scene).width();
if (extraWidth > 1) {
_sV -= Math.round(extraWidth / 2);
}
}
return _sV;
},
slideThumb: function () {
Expand Down Expand Up @@ -1140,4 +1147,4 @@
});
return this;
};
}(jQuery));
}(jQuery));
6 changes: 3 additions & 3 deletions dist/js/lightslider.min.js

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/js/lightslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
prevHtml: '',
nextHtml: '',
rtl: false,
centerSlide: false,
adaptiveHeight: false,
vertical: false,
verticalHeight: 500,
Expand Down Expand Up @@ -607,6 +608,12 @@
_sV += (parseInt($children.eq(i).width()) + settings.slideMargin);
}
}
if (settings.centerSlide) {
var extraWidth = elSize - $children.eq(scene).width();
if (extraWidth > 1) {
_sV -= Math.round(extraWidth / 2);
}
}
return _sV;
},
slideThumb: function () {
Expand Down Expand Up @@ -1137,4 +1144,4 @@
});
return this;
};
}(jQuery));
}(jQuery));

0 comments on commit 7d90ea7

Please sign in to comment.