Skip to content

Instantly share code, notes, and snippets.

@zaurmag
Last active September 25, 2017 12:42
Show Gist options
  • Save zaurmag/2eb7d5da301aeecd59bcfba9b321312a to your computer and use it in GitHub Desktop.
Save zaurmag/2eb7d5da301aeecd59bcfba9b321312a to your computer and use it in GitHub Desktop.
Фиксация меню при прокрутке страницы
// ======= Fixed block =======
(function($) {
$.fn.addFixClass = function(options) {
options = $.extend({
offset: 200,
destroy: false
}, options);
var fixClass = $(this);
$(window).bind('scroll', function() {
if ($(window).scrollTop() >= options.offset && !options.destroy) {
$(fixClass).addClass("fixed");
setTimeout(function() {
$(fixClass).addClass("animate");
}, 500);
} else {
$(fixClass).removeClass("fixed");
setTimeout(function() {
$(fixClass).removeClass("animate");
}, 500);
}
});
if (options.destroy) {
$(window).unbind('scroll');
$(fixClass).removeClass('fixed animate');
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment