Parallax navigation menu to change colors on specific slides

ethiokid

I'm building a parallax website and I wanted my parent navigation and its child to change color on specific slides so as to be visible. What code should I use in jQuery to achieve this?

This is my CSS, markup and code:

.navigation{
    font-family:thin lines and curves;
    position:fixed;
    text-align:center;
    letter-spacing:1px;
    z-index:51;
    top:50%;
    left:6%;
}

.navigation li{
    font-family:thin lines and curves;
    color:#fff;
    display:block;
    letter-spacing:2px;
    padding:0 10px;
    line-height:30px;
    margin-bottom:2px;
    margin-left:auto;
    margin-right:auto;
    -webkit-transition: all .2s ease-in-out;
}
.navigation li:hover,
.active{
    font-family:thin lines and curves;
    cursor:pointer;
    text-decoration:underline;
}

.navigation2{
    font-family:thin lines and curves;                                   /*EC2127 - red color tone of logo*/
    position:fixed;
    text-align:right;
    letter-spacing:1px;
    top:50%; 
    left:88%;
    z-index:51;
    }
.navigation2 li{
    font-family:thin lines and curves;
    color:#fff;
    display:block;
    letter-spacing:2px;
    padding:0 10px;
    line-height:30px;
    margin-bottom:2px;
    margin-left:auto;
    margin-right:auto;
    -webkit-transition: all .2s ease-in-out;
}
.navigation2 li:hover,.active{
    font-family:thin lines and curves;
    cursor:pointer;
    text-decoration:underline;







<ul class="navigation">
    <li data-slide="1"><img class="geshalogo" src="images/geshalogo.png"></li>
        <li data-slide="2">estate
                <ul class="navigation2">
                <li data-slide="2">land</li>
                <li data-slide="3">varietal</li>
                <li data-slide="4">people</li>
                <li data-slide="6">practices</li>
                <li data-slide="9">future offerings</li>
                </ul>
        </li>
        <li data-slide="10">about</li>
        <li data-slide="13">location</li>
        <li data-slide="14">contact</li>
    </ul>







jQuery(document).ready(function ($) {


    //initialise Stellar.js
    $(window).stellar();

    //Cache some variables

    var links = $('.navigation').find('li');
    var link = $('.navigation2').find('li'); // informs to cache a second set of navigation and sets it to play
    slide = $('.slide');
    button = $('.button');
    mywindow = $(window);
    htmlbody = $('html,body');


    //Setup waypoints plugin

    slide.waypoint(function (event, direction) {

        //cache the variable of the data-slide attribute associated with each slide

        dataslide = $(this).attr('data-slide');

        //If the user scrolls up change the navigation link that has the same data-slide attribute as the slide to active and 
        //remove the active class from the previous navigation link

        if (direction === 'down') {
            $('.navigation li[data-slide="' + dataslide + '"]').addClass('active').prev().removeClass('active');
        }
                // else If the user scrolls down change the navigation link that has the same data-slide attribute as the slide to active and 
        //remove the active class from the next navigation link

        else {
            $('.navigation li[data-slide="' + dataslide + '"]').addClass('active').next().removeClass('active');
        }
        // same as the aboove for the second set of navigations

        if (direction === 'down') {
           $('.navigation2 li[data-slide="' + dataslide + '"]').addClass('active').prev().removeClass('active');
        }
        else {
           $('.navigation2 li[data-slide="' + dataslide + '"]').addClass('active').next().removeClass('active');
       }

    });

    //waypoints doesnt detect the first slide when user scrolls back up to the top so we add this little bit of code, that removes the class 
    //from navigation link slide 2 and adds it to navigation link slide 1.

    mywindow.scroll(function () {
        if (mywindow.scrollTop() == 0) {
            $('.navigation li[data-slide="1"]').addClass('active');
            $('.navigation li[data-slide="2"]').removeClass('active');
        }
    });

    mywindow.scroll(function () {
        if (mywindow.scrollTop() == 0) {
            $('.navigation2 li[data-slide="1"]').addClass('active');
            $('.navigation2 li[data-slide="2"]').removeClass('active');
        }
    });

    //Create a function that will be passed a slide number and then will scroll to that slide using jquerys animate. The Jquery
    //easing plugin is also used, so we passed in the easing method of 'easeInOutQuint' which is available throught the plugin.

    function goToByScroll(dataslide) {
        htmlbody.animate({
            scrollTop: $('.slide[data-slide="' + dataslide + '"]').offset().top
        }, 2000, 'easeInOutQuint');
    }

    //When the user clicks on the navigation links, get the data-slide attribute value of the link and pass that variable to the goToByScroll function

    links.click(function (e) {
        e.preventDefault();
        dataslide = $(this).attr('data-slide');
        goToByScroll(dataslide);
    });

    //When the user clicks on the button, get the get the data-slide attribute value of the button and pass that variable to the goToByScroll function

    button.click(function (e) {
        e.preventDefault();
        dataslide = $(this).attr('data-slide');
        goToByScroll(dataslide);

    });

    $('.navigation2').hide(); //Hide children by default

    $('.navigation').children().click(function(){
    $(this).siblings().children('.navigation2').hide();
    $(this).children('.navigation2').slideToggle(2000, 'easeInOutQuint');     
    }).children('.navigation2').click(function (event) {
        event.stopPropagation();
    });


    });
Alex Tselegidis

Regarding the way your code is written there is only one thing to do for applying different colors based on the current active slide.

First declare an array of objects that represent each slide's visual settings that you'll need:

var slideSettings = [
   { 'links': '#AAA', 'background': '#FFF', 'image': 'http://url-to-an-image1.png' },
   { 'links': '#BBB', 'background': '#FFF', 'image': 'http://url-to-an-image2.png' }
   // add more colors here ...
];

After that whenever the user changes the current slide (scrolls up or down) you are going to apply the current slide settings to the navigation elements that need to be changed.

// ... whenever the user changes the current slide
$('.navigation li').css('color', slideSettings[dataslide].links);
$('.navigation li').css('background-color', slideSettings[dataslide].background);
$('.navigation li img').attr('src', slideSettings[dataslide].image);
// ... continue with the rest ...

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to change items in navigation menu

분류에서Dev

jQuery animate() on hover navigation menu

분류에서Dev

Sub menu in specific location

분류에서Dev

top div wont change background colors

분류에서Dev

How can I change the colors of the slices of the pie?

분류에서Dev

How to implement slide navigation menu in sencha touch

분류에서Dev

Need to check div visibility to create "navigation menu"

분류에서Dev

Dropdown navigation menu <li> centering issue

분류에서Dev

Variable number of menu-items with all different colors

분류에서Dev

Delphi change color of main menu

분류에서Dev

change icon on menu link click

분류에서Dev

Change the text color of the popup menu

분류에서Dev

Is it possible to insert a menu item at a specific position in Dijit using Dijit/Menu

분류에서Dev

Grub: configuration to boot on specific partition without menu

분류에서Dev

Android: how to change the background colors of listitems in a listview, managed by SimpleCursorAdapter

분류에서Dev

How to change button colors wth javascript with multiple buttons?

분류에서Dev

how to change colors of my ps1 root terminal permanently

분류에서Dev

Change terminal colors when connecting to remote server, Linux

분류에서Dev

Change the order of navigation in my account page in magento

분류에서Dev

Chrome - change page navigation keys in pdf viewer

분류에서Dev

how to change buttons to menu in android eclipse

분류에서Dev

How to change a vertical css menu to a horizontal one

분류에서Dev

How to change the menu active link while scrolling?

분류에서Dev

Change Default Font for a Specific Language

분류에서Dev

JQuery Parallax not working

분류에서Dev

How can i check if an item is part of a specific menu [Joomla 3.3]

분류에서Dev

windows program, top bar menu, add item to specific program

분류에서Dev

Navigation Drawer change the Icon and text color of highlighted item

분류에서Dev

Cannot change text and background color of searchbar in navigation bar

Related 관련 기사

  1. 1

    How to change items in navigation menu

  2. 2

    jQuery animate() on hover navigation menu

  3. 3

    Sub menu in specific location

  4. 4

    top div wont change background colors

  5. 5

    How can I change the colors of the slices of the pie?

  6. 6

    How to implement slide navigation menu in sencha touch

  7. 7

    Need to check div visibility to create "navigation menu"

  8. 8

    Dropdown navigation menu <li> centering issue

  9. 9

    Variable number of menu-items with all different colors

  10. 10

    Delphi change color of main menu

  11. 11

    change icon on menu link click

  12. 12

    Change the text color of the popup menu

  13. 13

    Is it possible to insert a menu item at a specific position in Dijit using Dijit/Menu

  14. 14

    Grub: configuration to boot on specific partition without menu

  15. 15

    Android: how to change the background colors of listitems in a listview, managed by SimpleCursorAdapter

  16. 16

    How to change button colors wth javascript with multiple buttons?

  17. 17

    how to change colors of my ps1 root terminal permanently

  18. 18

    Change terminal colors when connecting to remote server, Linux

  19. 19

    Change the order of navigation in my account page in magento

  20. 20

    Chrome - change page navigation keys in pdf viewer

  21. 21

    how to change buttons to menu in android eclipse

  22. 22

    How to change a vertical css menu to a horizontal one

  23. 23

    How to change the menu active link while scrolling?

  24. 24

    Change Default Font for a Specific Language

  25. 25

    JQuery Parallax not working

  26. 26

    How can i check if an item is part of a specific menu [Joomla 3.3]

  27. 27

    windows program, top bar menu, add item to specific program

  28. 28

    Navigation Drawer change the Icon and text color of highlighted item

  29. 29

    Cannot change text and background color of searchbar in navigation bar

뜨겁다태그

보관