Tagged: , ,

Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • #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
    Richard

    #846372

    Half 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

    #847268

    Hi,
    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-656372

    Best regards,
    Mike

    #847356

    Thanks 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

    #847395

    Hi,
    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,
    Mike

    #847399

    Hi 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

    #847457

    Hi,
    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,
    Mike

    #847467

    Hi 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

    #847474

    Hi,
    That’s odd, it seems to work on my end, did you try clearing your cache please see screenshot in Private Content area

    Best regards,
    Mike

    #847476

    Hi 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

    #847479

    Hi,
    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,
    Mike

    #847495

    Hi 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

    #847836

    Hi,
    I’m sorry, but I don’t see it, did you see it in the video? How many pixels high is it?

    Best regards,
    Mike

    #847863

    Hiya. 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 adding margin-top:40px to the submenu. However as the element above is not fixed across the site it’s hard to replicate dynamically.

    Richard

    #848612

    Hi Richard,

    Please check you JavaScript, there is an error there.

    Best regards,
    Victoria

    #848616

    Thanks Victoria, would you happen to know how to fix.

    Thanks
    Richard

    #849797

    Hi,

    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,
    Ismael

    #849899

    Hi 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

    #850178

    Hi,
    Thank you for sharing the solution, we will close this now. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 19 posts - 1 through 19 (of 19 total)
  • The topic ‘Fixed small header but main scrolls’ is closed to new replies.