Created
December 10, 2016 15:56
-
-
Save DmitriyRF/98f24353eb5d1487ac16eb68ea7d5a37 to your computer and use it in GitHub Desktop.
Плавающий блок, который фиксируется на экране в пределах двух областей
This file contains hidden or 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
//Фиксация меню при прокрутке до уровня ------------+-------------------------+-------------------------+-------------------------+------------- | |
var h_hght = 225; // высота шапки | |
var h_mrg = 25; // отступ когда шапка уже не видна, т.е. от верхнего окна | |
var h_mnhght = 0; // максимальный отступ, т.е. нижний предел прокрукти блока, при "0" прокручивается до конца страницы | |
$(window).scroll(function(){ | |
//отступ сверху | |
var top = $(this).scrollTop(); | |
// элемент | |
var elem = $('#top_nav'); | |
//высота элемента | |
var h_elem = elem.height(); | |
if (top+h_mrg < h_hght) { | |
elem.css('top', (h_hght-top)); | |
} else { | |
elem.css('top', h_mrg); | |
} | |
if (top+h_mrg+h_elem > h_mnhght && h_mnhght != 0) { | |
elem.css('top', (h_mnhght-top-h_elem-h_mrg)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment