Skip to content

Instantly share code, notes, and snippets.

@d1i1m1o1n
Created November 20, 2015 08:13
Show Gist options
  • Save d1i1m1o1n/fb486d115f37aa07e2f8 to your computer and use it in GitHub Desktop.
Save d1i1m1o1n/fb486d115f37aa07e2f8 to your computer and use it in GitHub Desktop.
Fixed block while scroll page
//Фиксируем форму обратной связи
var $section_of_form = $("#fixed_scroll_form").closest('section'),
fixed_scroll_form = $section_of_form.offset().top - 50;
//Выставляем текущую ширину
$section_of_form.css('width', $section_of_form.css('width'));
$(window).bind("scroll", function() {
var offset = $(this).scrollTop();
if (offset >= fixed_scroll_form && !$section_of_form.hasClass("fixed_scroll_form")) {
$section_of_form.addClass('fixed_scroll_form');
} else if (offset < fixed_scroll_form) {
$section_of_form.removeClass('fixed_scroll_form');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment