Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1279187
    TactikMedia
    Participant

    Hello,

    I am trying to make a sticky section appear at the top of one of my pages. I have found the following post (https://community.theme.co/forums/topic/fixed-section/) on how to make it work but at some point the sticky section starts to flicker at some point when we scroll down, as if the if/else condition was entered a couple of times in a simple scroll.

    I have tried to debug the jQuery myself but no dice. Here’s the code I currently have :

    CSS

    .x-section.fixed-section {
        margin: 0px;
        padding: 0px;
        visibility: visible;
        position: fixed;
        z-index: 1;
        display: inline;
        width: 100%;
        top: 30px !important; 
    }

    jQuery

    jQuery(function($){
      $(window).scroll(function(){
        var navbarHeight = $('.x-navbar').height() + $('.x-topbar').height() + $('#wpadminbar').height() + 0;
        if( $(this).scrollTop() >= $('.x-main').offset().top - navbarHeight && $(window).width() > ( $('#fixed-sec').offset().top - navbarHeight ) ) {
          $('#fixed-sec').addClass('fixed-section').css({ top: 0 });
        } else {
          $('#fixed-sec').removeClass('fixed-section');
        }
      })
    });
    #1279192
    TactikMedia
    Participant
    This reply has been marked as private.
    #1279507
    Rue Nel
    Moderator

    Hello There,

    Thanks for writing us in! Please have your JS code updated and make use of this code instead:

    jQuery(function($){
      $(window).scroll(function(){
        var navbarHeight = $('.x-navbar').height() + $('.x-topbar').height() + $('#wpadminbar').height() + 0;
    
        console.log($('#fixed-sec').offset().top);
        if( $(this).scrollTop() >= $('.x-main').offset().top && $(window).width() > $('#fixed-sec').offset().top ) {
          $('#fixed-sec').addClass('fixed-section').css({ top: 0 });
        } else {
          $('#fixed-sec').removeClass('fixed-section');
        }
      })
    });

    Please let us know if this works out for you.

    #1280686
    TactikMedia
    Participant

    I have updated the JS code but the fixed section keeps flickering once I reach the middle of the page and lower.

    Edit : figured out it is to debug actually

    #1280952
    Lely
    Moderator

    Glad you were able to figure this out.

    Cheers!

    #1280963
    TactikMedia
    Participant

    Uh? Problem clearly is not figured out yet…

    #1281063
    Rue Nel
    Moderator

    Hello There,

    Thanks for updating in! Please have the JS code updated and use this instead:

    jQuery(function($){
      $(window).scroll(function(){
        var navbarHeight = $('.x-navbar').height() + $('.x-topbar').height() + $('#wpadminbar').height() + 0;
    
        console.log($('#fixed-sec').offset().top);
        if( $(this).scrollTop() >= $('.x-main').offset().top && $(window).width() > $('#fixed-sec').offset().top ) {
          $('#fixed-sec').addClass('fixed-section');
        } else {
          $('#fixed-sec').removeClass('fixed-section');
        }
      })
    });

    Please let us know how it goes.

    #1281551
    TactikMedia
    Participant

    Hello, I have updated the code but the problem still occurs.

    #1281591
    Christian
    Moderator

    Please remove all the code given previously and use a plugin like https://wordpress.org/plugins/sticky-menu-or-anything-on-scroll/

    Please take note though that since this is a third party plugin, issue arising from the use of it or further modification is outside the scope of our support.

    Thanks.

    #1281610
    TactikMedia
    Participant

    Thanks Christian, the plugin worked fine.

    #1281652
    Christian
    Moderator

    You’re welcome.

  • <script> jQuery(function($){ $("#no-reply-1279187 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>