changing of the header from 1 to 2 when scrolling !
-
hello,
I want when I scroll to change header from header 1 to header 2
so I found this javascript code :<script> cons header=document.querySellctor ("header"); window.addEventListener ('scroll',() => { if (window.scrollY > 0) { header.classList.add ("change-site-header") ; } else { header.classList.remove ("change-site-header") ; } })
I make this htl code :
<header> <div class="flex-container-site-header "> <!-- site-header --> </div> <div class="change-site-header"> aaa </div> </header>
css code of first header is :
.flex-container-site-header { display:flex; flex-direction:row; justify-content:space-between; align-items:center; margin-top:0; width:100%; height: 80px; background-color:#343a40; box-sizing: border-box; position:fixed; z-index: 1; }
and css code of second header is :
.change-site-header { display:flex; flex-direction:row; justify-content:space-between; align-items:center; margin-top:0; width:100%; height: 80px; box-sizing: border-box; position:fixed; z-index: 1; background-color:red; }
now my questions are :
1- do I have to implement javascript in my theme to let the script work? for example cdn or in function.php ?2- is my html code above is OK or it is wrong? if it is wrong what do I have to change?
for the question 1 I have inserted this code (for javascript)in my function.php
function auto_garage_scripts_function() { wp_enqueue_script( 'js-file', get_template_directory_uri() . '/js/myscript.js'); } add_action('wp_enqueue_scripts','auto_garage_scripts_function');
is this code in function.php is OK?
very short answers wil be enough.thanks
The page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.