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

Included maxWidth option #122

Closed
wants to merge 1 commit into from
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ var b = $.isScrollToFixed('.header');
* __postAbsolute__ - the function handler triggered just after the element leaves absolute.
* __offsets__ - (true|false|not present) some websites have needed an adjustment to the left position of the element due to something in their layout. This option turns this adjustment on.
* __minWidth__ (number) - the minimum width the window must be to "fix" the target element. Turns off the functionaility when the window width is less than specified.
* __maxWidth__ (number) - the maximum width the window must be to "fix" the target element. Turns off the functionaility when the window width is more than specified.
* __dontCheckForPositionFixedSupport__ - (true|false|not present) some devices do not support position fixed; we check to see if it does. This option turns off that check if set to true.
* __dontSetWidth__ - (true|false|not set) box sizing that does not set the width on the target element when it goes fixed or absolute.
* __removeOffsets__ - (true|false|not set) recalculate top offset and delete left offset when the element goes absolute.
Expand Down
2 changes: 1 addition & 1 deletion jquery-scrolltofixed-min.js

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

17 changes: 12 additions & 5 deletions jquery-scrolltofixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var position;
var originalPosition;

var originalOffset;
var originalOffsetTop;

// The offset top of the element when resetScroll was called. This is
// used to determine if we have scrolled past the top of the element.
Expand Down Expand Up @@ -193,7 +193,7 @@
'width' : '',
'position' : originalPosition,
'left' : '',
'top' : originalOffset.top,
'top' : originalOffsetTop,
'margin-left' : ''
});

Expand Down Expand Up @@ -262,6 +262,13 @@
setUnfixed();
target.trigger('unfixed.ScrollToFixed');
}
} else if (base.options.maxWidth && $(window).width() > base.options.maxWidth) {
if (!isUnfixed() || !wasReset) {
postPosition();
target.trigger('preUnfixed.ScrollToFixed');
setUnfixed();
target.trigger('unfixed.ScrollToFixed');
}
} else if (base.options.bottom == -1) {
// If the vertical scroll position, plus the optional margin, would
// put the target element at the specified limit, set the target
Expand Down Expand Up @@ -355,7 +362,7 @@
if(target.is(':visible')) {
isReset = false;
checkScroll();
}
}
}

var windowScroll = function(event) {
Expand Down Expand Up @@ -428,7 +435,7 @@
position = target.css('position');
originalPosition = target.css('position');

originalOffset = $.extend({}, target.offset());
originalOffsetTop = target.css('top');

// Place the spacer right after the target element.
if (isUnfixed()) base.$el.after(spacer);
Expand Down Expand Up @@ -522,4 +529,4 @@
(new $.ScrollToFixed(this, options));
});
};
})(jQuery);
})(jQuery);