From 654789d40a13aa1fe82453350ff46dfcede1f1b8 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 28 Nov 2014 09:32:48 +0100 Subject: [PATCH] Sticky for not firefox --- Resources/views/layout.html.twig | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index f1830d04d..6ed6b7d8b 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -165,6 +165,41 @@ }); $('.select2').select2(); + + + $('.sticky-form-buttons').each(function(i,stick_element) { + if($(stick_element).css('position') !== 'sticky') { + var sticky_form_buttons_offset_top = $(stick_element).offset().top; + + function stickyEmulate() { + if (($(window).scrollTop() + $(window).height()) < sticky_form_buttons_offset_top) { + //sticky at bottom + $(stick_element).css('position','fixed'); + $(stick_element).css('bottom','0'); + $(stick_element).css('top',''); + $(stick_element).css('width',$(stick_element).parent().outerWidth()); + } else if (sticky_form_buttons_offset_top < $(window).scrollTop()) { + //sticky at top + $(stick_element).css('position','fixed'); + $(stick_element).css('top','0'); + $(stick_element).css('bottom',''); + $(stick_element).css('width',$(stick_element).parent().outerWidth()); + } else { + //no sticky + $(stick_element).css('position','initial'); + $(stick_element).css('bottom',''); + $(stick_element).css('width',''); + $(stick_element).css('top',''); + } + } + + $(window).scroll(function() { + stickyEmulate(); + }); + + stickyEmulate(); + } + });