-
AuthorPosts
-
August 31, 2017 at 3:44 pm #846306
Hi there
I’m trying to achieve a ‘fixed’ small header above the main header (which will scroll) but can’t get it right. It also doesn’t help that i’ve got a full width submenu that needs positioning so it doesn’t clash.
Any help would be very much appreciated
RichardAugust 31, 2017 at 4:42 pm #846372Half way there with
#header_main { height: 100px !important; top: 30px; } #header_meta { position: fixed; width: 100%; top: 30px; }
But still need some help changing the sticky position of the submenu.
Thanks
September 3, 2017 at 4:23 am #847268Hi,
I found a post with a code snippet that addresses a similar issue, you may find this useful : https://kriesi.at/support/topic/hellobar-and-sticky-sub-menu-conflict/#post-656372Best regards,
MikeSeptember 3, 2017 at 10:27 am #847356Thanks Mike
I’ve had a look and it’s partially solved the problem with this adjustment
// custom script function add_custom_script(){ ?> <script> (function($){ function g() { var scrolled = $('.header-scrolled').length; if( scrolled == 1 ) { $('#sub_menu1').css('margin-top', '0px'); } else { $('#sub_menu1').css('margin-top', '30px'); } } $(window).scroll(function() { g(); }); })(jQuery); </script> <?php } add_action('wp_footer', 'add_custom_script');
However the pixels added to the margin remain even when the user scrolls back the other way.
Ideally I need to change the start position of the sticky when it hits the top of the browser.
Richard
September 3, 2017 at 3:42 pm #847395Hi,
I don’t understand, when I scroll back and forth it all looks very slick, perhaps you could add a screenshot of what you mean?Best regards,
MikeSeptember 3, 2017 at 4:08 pm #847399Hi Mike
The grey navigation is not supposed to have the padding above it. The menu items should be sitting central in a box only 30px deep.
Richard
September 3, 2017 at 10:02 pm #847457Hi,
OK, this is for the dark gray sub-menu:#top .av-submenu-container, #menu-categories-home {max-height: 30px!important; } #top .av-subnav-menu > li {padding: 5px 0!important; } #top .av-subnav-menu a .avia-menu-fx {top: 32px !important; }
I see the code is calling min-height, but I believe max-height would be better, that is why I used it here.
Before I started this time, I saw your sub-menu is going behind the top bar again, unlike this morning when it snapped to the top bar. So I can’t tell if this code conflicts with that action, are you going to put it back?Best regards,
MikeSeptember 3, 2017 at 10:36 pm #847467Hi Mike
Thanks for looking again and yes I’ve been messing with some custom JS to control the start point. Currently seeing if this will work
add_action( 'wp_footer', 'enfold_customization_custom_scripts' ); function enfold_customization_custom_scripts() { ?> <script type = "text/javascript"> jQuery(document).ready(function(){ // var menu = document.querySelector('#sub_menu1') var menuPosition = menu.getBoundingClientRect().top; window.addEventListener('scroll', function() { if (window.pageYOffset >= menuPosition) { menu.style.position = 'fixed'; menu.style.top = '40px'; } else { menu.style.position = 'static'; menu.style.top = ''; } }); // </script> <?php }
Unfortunately the CSS adjustments you suggested don’t work. Will keep trying.
Richard
September 3, 2017 at 11:06 pm #847474Hi,
That’s odd, it seems to work on my end, did you try clearing your cache please see screenshot in Private Content areaBest regards,
MikeSeptember 3, 2017 at 11:24 pm #847476Hi Mike
The initial appearance on scroll sticks to the top in the right place, but when you scroll back down you’ll see the white space appear. I’ve reverted to the code from earlier and added you changes.
Richard
September 3, 2017 at 11:39 pm #847479Hi,
Do you mean that when you scroll back down to the point where it was on the page, below the slider, it hooks on there again?
It seems that it should do that, see the video in Private Content area of what I see, in Chrome on Win10.Best regards,
MikeSeptember 4, 2017 at 12:22 am #847495Hi Mike
No that part is working OK, it’s the white space above the grey box that only appears after the initial scroll that’s annoying me.
Richard
September 4, 2017 at 5:30 pm #847836Hi,
I’m sorry, but I don’t see it, did you see it in the video? How many pixels high is it?Best regards,
MikeSeptember 4, 2017 at 7:19 pm #847863Hiya. I’ve been adjusting code so it may look different now. The space is 40px. I found a CSS hack by adding
margin-bottom:-40px
to the div above the submenu and then addingmargin-top:40px
to the submenu. However as the element above is not fixed across the site it’s hard to replicate dynamically.Richard
September 6, 2017 at 1:29 pm #848612Hi Richard,
Please check you JavaScript, there is an error there.
Best regards,
VictoriaSeptember 6, 2017 at 1:33 pm #848616Thanks Victoria, would you happen to know how to fix.
Thanks
RichardSeptember 9, 2017 at 3:31 am #849797Hi,
Please try to use the previous script modification but instead of checking if the “header-scrolled” class is present, check for the vertical scroll position with the scrollTop function.
// https://api.jquery.com/scrollTop/
Best regards,
IsmaelSeptember 9, 2017 at 9:36 am #849899Hi Ismael
Thanks for the suggestion. In the end this script worked a treat, for any one else needing a solution
<script> (function($){ var calc_scroll = function() { var header = $('#header').height(), scroll = $(window).scrollTop(); if(scroll >= 450) { $('#sub_menu1').css('padding-top', '30px'); } else { $('#sub_menu1').css('padding-top', '0px'); } } $(window).scroll(function() { calc_scroll(); }); })(jQuery); </script>
Adjust your scroll height for where the navigation starts and padding for when it hits the top of the browser window
Richard
September 10, 2017 at 7:38 pm #850178 -
AuthorPosts
- The topic ‘Fixed small header but main scrolls’ is closed to new replies.