Created
May 21, 2018 19:49
-
-
Save zaurmag/788f714920a5e63c1f957ee8698352d0 to your computer and use it in GitHub Desktop.
Fixed блок
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
// ======= 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