Skip to content
This repository was archived by the owner on Sep 11, 2022. It is now read-only.
Open
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
32 changes: 31 additions & 1 deletion jquery.sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
getWidthFrom: '',
widthFromWrapper: true, // works only when .getWidthFrom is empty
responsiveWidth: false,
zIndex: 'inherit'
zIndex: 'inherit',
scrollStickyElement: false
},
$window = $(window),
$document = $(document),
sticked = [],
windowHeight = $window.height(),
lastScroll = $window.scrollTop(),
stickyOffest = 0,
scroller = function() {
var scrollTop = $window.scrollTop(),
documentHeight = $document.height(),
Expand Down Expand Up @@ -76,6 +79,33 @@
} else {
newTop = s.topSpacing;
}

if (s.scrollStickyElement) {
//also scroll the sticky element if its higher from window
if (s.stickyElement.outerHeight() > windowHeight) {
var scrollDiff = scrollTop - lastScroll;
var newStickyOffest = stickyOffest - scrollDiff;

if (scrollDiff > 0) {
//down
if ((s.stickyElement.outerHeight() + stickyOffest) > windowHeight) {
stickyOffest = newStickyOffest;
if (stickyOffest < (windowHeight - s.stickyElement.outerHeight())) {
stickyOffest = windowHeight - s.stickyElement.outerHeight();
}
}
newTop = stickyOffest;
} else if (s.currentTop < 0) {
//up
newTop = stickyOffest = newStickyOffest;
} else {
newTop = 0;
}
}
}

lastScroll = scrollTop;

if (s.currentTop !== newTop) {
var newWidth;
if (s.getWidthFrom) {
Expand Down