Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix padding-top for animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey Razbakov authored Jan 17, 2017
1 parent f9cb15a commit e3ff146
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions sticky-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ var jQuery = require('jquery');
if (isSticky) {
stickyTimer = setTimeout(function () {
$element.addClass("is-sticky");
$body.css('padding-top', stickyElementHeight);
}, stickyTimeout);
} else {
stickyTimer = setTimeout(function () {
$body.css('padding-top', stickyElementHeight);
$element.removeClass("is-sticky");
}, stickyTimeout);
}
Expand All @@ -54,6 +52,7 @@ var jQuery = require('jquery');
$body = $('body');

stickyElementHeight = $stickyElement.height();
var offsetTop = $stickyElement.offset().top;

var stickyTargetVal = $stickyElement.data('sticky').target;
if (stickyTargetVal) {
Expand All @@ -64,7 +63,7 @@ var jQuery = require('jquery');
if (stickyMinTopVal) {
stickyMinTop = stickyMinTopVal;
} else {
stickyMinTop = stickyElementHeight;
stickyMinTop = offsetTop;
}

var stickyTypeVal = $stickyElement.data('sticky').type;
Expand All @@ -91,14 +90,14 @@ var jQuery = require('jquery');
// Scrolled to top or Scrolling down
makeSticky($stickyElement, $body, false);

if (scrollbarVerticalPosition <= stickyElementHeight) {
if (scrollbarVerticalPosition <= stickyMinTop) {
$body.addClass('sticky-top');
$body.css('padding-top', 0);
$stickyElement.removeClass("sticky-wrapper");
$body.css('padding-top', 0);
} else {
$body.removeClass('sticky-top');
$stickyElement.addClass("sticky-wrapper");
$body.css('padding-top', stickyElementHeight);
$stickyElement.addClass("sticky-wrapper");
}
} else {
// Scrolling up
Expand Down

0 comments on commit e3ff146

Please sign in to comment.