Created
January 15, 2019 07:56
-
-
Save andrey-helldar/42519480c6a1c4248888355a2983b3a7 to your computer and use it in GitHub Desktop.
fly header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.flyHead = function () { | |
function t() { | |
let t; | |
'absolute' == i.css('position') ? t = -a.height : (t = parseInt(i.css('top')) - n.step, t = -t > a.height ? -a.height : t), i.css({ | |
top: t, | |
position: 'fixed' | |
}) | |
} | |
function o() { | |
let t = parseInt(i.css('top')) - n.step; | |
t = t > 0 ? 0 : t, i.css({top: t}), e() | |
} | |
function e() { | |
i.css({backgroundPosition: '0 -' + n.val + 'px'}) | |
} | |
let i = this, a = {height: 0, top: 0}, n = {last: 0, val: 0, step: 0}; | |
$(window).scroll(function () { | |
a.height = i.height(), a.top = i.offset().top, n.val = $(this).scrollTop(), n.step = n.val - n.last, n.step < 0 ? o() : t(), n.last = n.val | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Шапка сайта "плавно" скрывается при прокрутке страницы вниз и появляется при прокрутке вверх.
Использовать очень просто:
Example: https://jsfiddle.net/Helldar/9m7xupz1/10/