Page Specific Javascript for Navbar
-
Hello everyone,
This is my first time using the forum, so lease forgive any mistakes I make but I am after a little bit of help with some JavaScript. I am using it for the very time and found a nice bit of code that allows me to set an anchor point for when my menu bar appears upon scrolling. A very similar effect to what you see here https://www.laurenlibaw.com
What I need help with is that I need the affect to only take place on the home page as some of the other pages are none scrolling pages.
I am using X-Theme which allows you to add CSS and Java Script in the WordPress Customizer.
This is the code I am using for the effect.
CSS:
body.x-navbar-fixed-top-active .x-navbar-wrap { height: 0px; margin-bottom: 0px }
Javascript:
(function ($) { $(document).ready(function(){ // hide .x-navbar first $(".x-navbar").hide(); // fade in .x-navbar $(function () { $(window).scroll(function () { // set distance user needs to scroll before we start fadeIn if ($(this).scrollTop() > 450) { $('.x-navbar').fadeIn(); } else { $('.x-navbar').fadeOut(); } }); }); }); }(jQuery));
I did quite a bit of research and what I found so far is this:
if( is_page('x')) { ?> // YOUR SCRIPT STUFF <?php }
Is this what I would need? I have tried experimenting with this bit of code but can not get it to work.
Any help would be most appreciated.
The website in question is https://www.nicodevilliers.com
Please note I have removed the function for the moment as it is a live site.
Thank you,
Daniel
- The topic ‘Page Specific Javascript for Navbar’ is closed to new replies.