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

Added alwaysFixToTop option to ignore viewport height and always fix sidebar to the top of the screen when it is sticky #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
13 changes: 10 additions & 3 deletions src/sticky-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ const StickySidebar = (() => {
* The sidebar returns to its normal position if its width below this value.
* @type {Numeric}
*/
minWidth: false
minWidth: false,

/**
* Ignore the viewport size and always affix the sidebar to the top of the screen when it is sticky.
* If the sidebar is taller than the screen, it will not require scrolling to the bottom of the sidebar before making it sticky.
* @type {Boolean}
*/
alwaysFixToTop: false
};

// ---------------------------------
Expand Down Expand Up @@ -341,7 +348,7 @@ const StickySidebar = (() => {
var colliderBottom = dims.viewportBottom - dims.bottomSpacing;
var affixType = this.affixedType;

if( this.isSidebarFitsViewport() ){
if( this.isSidebarFitsViewport() || this.options.alwaysFixToTop ){
if( dims.sidebarHeight + colliderTop >= dims.containerBottom ){
dims.translateY = dims.containerBottom - sidebarBottom;
affixType = 'CONTAINER-BOTTOM';
Expand Down Expand Up @@ -388,7 +395,7 @@ const StickySidebar = (() => {
dims.translateY = dims.containerBottom - sidebarBottom;
affixType = 'CONTAINER-BOTTOM';

} else if( ! this.isSidebarFitsViewport() ){
} else if( ! this.isSidebarFitsViewport() && ! this.options.alwaysFixToTop ){

if( dims.containerTop <= colliderTop &&
(0 !== dims.translateY && dims.maxTranslateY !== dims.translateY) ){
Expand Down