Tagged: x
-
AuthorPosts
-
December 2, 2016 at 2:52 pm #1279187
TactikMediaParticipantHello,
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'); } }) });December 2, 2016 at 2:54 pm #1279192
TactikMediaParticipantThis reply has been marked as private.December 2, 2016 at 9:30 pm #1279507
Rue NelModeratorHello 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.
December 4, 2016 at 1:35 pm #1280686
TactikMediaParticipantI 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
December 4, 2016 at 7:13 pm #1280952
LelyModeratorGlad you were able to figure this out.
Cheers!
December 4, 2016 at 7:23 pm #1280963
TactikMediaParticipantUh? Problem clearly is not figured out yet…
December 4, 2016 at 9:19 pm #1281063
Rue NelModeratorHello 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.
December 5, 2016 at 7:38 am #1281551
TactikMediaParticipantHello, I have updated the code but the problem still occurs.
December 5, 2016 at 8:20 am #1281591
ChristianModeratorPlease 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.
December 5, 2016 at 8:44 am #1281610
TactikMediaParticipantThanks Christian, the plugin worked fine.
December 5, 2016 at 9:19 am #1281652
ChristianModeratorYou’re welcome.
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1279187 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
