Home › Forums › JavaScript › change hover over menu bar list elements as we scroll down the page
- This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
September 26, 2016 at 2:21 am #245899KolaParticipant
I have a navbar with 6 different list elements like home,about etc. I want each of these li elements to hover as we scroll down through all the sections. I have used isVisible function which tells me if a section is visible in viewport or not….
Following is the code.This code works just fine while scrolling down.But if we scroll up again then 2 list elements are getting hover effect at the same time whenever two sections are in viewport simultaneously…Please help
var oneElementHasHoverEffect = 0;
$(window).scroll(function(){ if($("#aboutus").isVisible()) { if(oneElementHasHoverEffect == 0){ $(".aboutList").addClass("hoverEffect"); oneElementHasHoverEffect = 1; } } else{ $(".aboutList").removeClass("hoverEffect"); oneElementHasHoverEffect = 0; } if($("#parallax").isVisible()) { if(oneElementHasHoverEffect == 0){ $(".thinkList").addClass("hoverEffect"); oneElementHasHoverEffect = 1; } } else{ $(".thinkList").removeClass("hoverEffect"); oneElementHasHoverEffect = 0; } if($("#services").isVisible()) { if(oneElementHasHoverEffect == 0){ $(".toolList").addClass("hoverEffect"); oneElementHasHoverEffect = 1; } } else{ $(".toolList").removeClass("hoverEffect"); oneElementHasHoverEffect = 0; } });
September 26, 2016 at 5:25 am #245904JimmyParticipantNot sure about everyone else, but if you could perhaps add a demo of the navigation with your code (or indirect link to the site) it would make things a lot easier to debug.
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- The forum ‘JavaScript’ is closed to new topics and replies.