Skip to content

Instantly share code, notes, and snippets.

@zaurmag
Created May 21, 2018 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaurmag/788f714920a5e63c1f957ee8698352d0 to your computer and use it in GitHub Desktop.
Save zaurmag/788f714920a5e63c1f957ee8698352d0 to your computer and use it in GitHub Desktop.
Fixed блок
// ======= 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