Skip to content

Commit

Permalink
Merge pull request kenwheeler#766 from xitongzou/add-carousel-width-calc
Browse files Browse the repository at this point in the history
adding calculation for carousel width in breakpoints
  • Loading branch information
kenwheeler committed Nov 9, 2014
2 parents 1e3a514 + d3d01f6 commit 2ccb641
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions slick/slick.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
_.cssTransitions = false;
_.paused = false;
_.positionProp = null;
_.respondTo = null;
_.shouldClick = true;
_.$slider = $(element);
_.$slidesCache = null;
Expand All @@ -141,6 +142,7 @@
responsiveSettings = _.options.responsive || null;

if (responsiveSettings && responsiveSettings.length > -1) {
_.respondTo = _.options.respondTo || "window";
for (breakpoint in responsiveSettings) {
if (responsiveSettings.hasOwnProperty(breakpoint)) {
_.breakpoints.push(responsiveSettings[
Expand Down Expand Up @@ -493,7 +495,16 @@
Slick.prototype.checkResponsive = function() {

var _ = this,
breakpoint, targetBreakpoint;
breakpoint, targetBreakpoint, respondToWidth;
var sliderWidth = _.$slider.width();
var windowWidth = $(window).width();
if (_.respondTo === "window") {
respondToWidth = windowWidth;
} else if (_.respondTo === "slider") {
respondToWidth = sliderWidth;
} else if (_.respondTo === "min") {
respondToWidth = Math.min(windowWidth, sliderWidth);
}

if (_.originalSettings.responsive && _.originalSettings
.responsive.length > -1 && _.originalSettings.responsive !== null) {
Expand All @@ -502,10 +513,8 @@

for (breakpoint in _.breakpoints) {
if (_.breakpoints.hasOwnProperty(breakpoint)) {
if ($(window).width() < _.breakpoints[
breakpoint]) {
targetBreakpoint = _.breakpoints[
breakpoint];
if (respondToWidth < _.breakpoints[breakpoint]) {
targetBreakpoint = _.breakpoints[breakpoint];
}
}
}
Expand Down

0 comments on commit 2ccb641

Please sign in to comment.