Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to center target slide #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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));