How to use a Navigation-Part in JQuery (ul.nav li a)?
Hey guys!
I have a question about, how i can use a class for an jquery action.
Here my example:
- .balken {
- height: 100px;
- width: 100%;
- background-color: white;
- border-top: 5px solid lightskyblue;
- display: flex;
- }
This is a bar at the top, in it is a picture and a navigation bar, you can see that they a in a flexbox.
- .sticky {
- height: 50px;
- position: fixed;
- border-bottom: 2px solid red;
- border-top: 0px;
- }
When you will scroll, the class sticky will be added to the .balken. This means the height will reduzed to 50px.
This is the script for it and it works!
- $(document).ready(function(){
- $(window).scroll(function() {
- if ($(document).scrollTop() > 50) {
- $('.balken').addClass("sticky");
- } else {
- $('.balken').removeClass("sticky");
- }
- });
- });
Now i want to do this with the navigation bar, i want to change the padding:
- ul.nav li a {
- display: inline-block;
- color: black;
- padding: 24px 26px;
- text-decoration: none;
- transition: 0.3s;
- font-size: 30px;
- text-align: center;
- }
and the sticky:
- .stickynav {
- padding: 10px 14px;
- }
Now i tried to do this like this:
- $(document).ready(function(){
- $(window).scroll(function() {
- if ($(document).scrollTop() > 50) {
- $('.balken').addClass("sticky");
- $('ul.nav.li.a').addClass("stickynav");
- } else {
- $('.balken').removeClass("sticky");
- $("ul.nav.li.a").removeClass("stickynav");
- }
- });
- });
But this isn't working. So my question is, how can i edit the ul.nav li a? Is this even possible and how?
I hope you can help me!
Best regards,
D4niel