.addClass JS/JQUERY
-
Hi everyone,
I have a problem that have been trying to solve for the past 3 days, and it starts to getting me crazy. I have created child theme, linked my style sheet via my function.php sheet without any trouble.
What I want to do now is simply add a class to the header of my pages (which contains my navigation menu, logo, etc.) on scroll down to add a sticky navigation and also resize my logo, etc.: I am following this example
So, what I have done so far is:
sticky.js
function makeSticky() { var myWindow = jquery(window), myHeader = jquery(".site-header"); myWindow.scroll(function () { if (myWindow.scrollTop() === 0) { myHeader.removeClass("sticky-nav"); } else { myHeader.addClass("sticky-nav"); } }); }
functions.php
<?php function child_scripts() { wp_enqueue_script( 'sticky', get_template_directory_uri() . '/js/sticky.js', array(jquery), true ); } add_action( 'wp_enqueue_scripts', 'child_scripts' ); ?>
header.php
<head> <script type="text/javascript" src="/js/sticky.js"></script> </head> <body> jquery( function() { makeSticky(); }); </body>
The problem is that it does not work. When I check on Firebug if a class has been added to my header, nothing happen.
I feel like I miss something, such as jquery or calling my js but I can’t figure it out.
Thanks for any help
Teddy
- The topic ‘.addClass JS/JQUERY’ is closed to new replies.