Skip to content
This repository has been archived by the owner on Sep 11, 2022. It is now read-only.

Commit

Permalink
Added responsive breakpoint functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nneal committed Dec 12, 2012
1 parent e9829da commit 1685d1f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions jquery.sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,33 @@
className: 'is-sticky',
wrapperClassName: 'sticky-wrapper',
center: false,
getWidthFrom: ''
getWidthFrom: '',
responsiveBreakpoint: 0
},
$window = $(window),
$document = $(document),
sticked = [],
windowHeight = $window.height(),
scroller = function() {
placer();
},
resizer = function() {
windowHeight = $window.height();
placer();
},
placer = function () {
var scrollTop = $window.scrollTop(),
documentHeight = $document.height(),
dwh = documentHeight - windowHeight,
extra = (scrollTop > dwh) ? dwh - scrollTop : 0;
extra = (scrollTop > dwh) ? dwh - scrollTop : 0,
o = $.extend(defaults);

for (var i = 0; i < sticked.length; i++) {
var s = sticked[i],
elementTop = s.stickyWrapper.offset().top,
etse = elementTop - s.topSpacing - extra;

if (scrollTop <= etse) {
if (scrollTop <= etse || $window.width() < o.responsiveBreakpoint) {
if (s.currentTop !== null) {
s.stickyElement
.css('position', '')
Expand Down Expand Up @@ -66,9 +75,6 @@
}
}
},
resizer = function() {
windowHeight = $window.height();
},
methods = {
init: function(options) {
var o = $.extend(defaults, options);
Expand Down

1 comment on commit 1685d1f

@reddo
Copy link

@reddo reddo commented on 1685d1f Apr 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helped me with #97

Thanks a lot!

Please sign in to comment.