Adjust the navigation text and logo color as you scroll on the page

I am new to HTML and CSS and I am working on a website with PagePiling.js scrolling feature. I want to change the color of my logo image and navigation text dynamically as I scroll to the next section. Specifically, I only want the part of the logo and text that intersects with the next section to change color. This is hard to explain in English, but basically, when the logo and nav text enter the grey section, they should turn red or another color. You can see an example of this effect in this CodePen demo. My website is hosted at .

HTML:

<!DOCTYPE html>
<html>
<head>
<title>InGadget | Your source for all gadget news!</title>

<link href="style.css" rel="stylesheet" type="text/css">

<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet">

<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/jquery.pagepiling.js"></script>

    <script>
        $(document).ready(function() {
            $('#pagepiling').pagepiling();
        });
    </script>

</head>
<body>

    <div class="navbar">
        <a id="logo" href="index.html"></a>
        <div class="nav">
            <a href="index.html">Home</a>
            <a href="#">News</a>
            <a href="#">Forum</a>
            <a href="#">Things I &#10084;</a>
            <a href="#">Contact</a>
        </div>
    </div>

    <div id="pagepiling">

        <div class="section" id="header">
            <div class="header-content-container">
                <div class="header-content">
                    <h1>Oculus Rift<br>
                        Next-generation Virtual Reality.</h1>
                </div>
            </div>
        </div>

        <div class="section" id="section1">
            Placeholder
        </div>

        <div class="section" id="section2">
            Placeholder
        </div>

        <div class="section" id="section3">
            Placeholder
        </div>

    </div>

</body>
</html>

CSS:

/* Styles */
@font-face {
    font-family: Neusa-SemiBold;
    src: url(fonts/neusa/Neusa-SemiBold.otf);
}

@font-face {
    font-family: Neusa-ExtraBold;
    src: url(fonts/neusa/Neusa-ExtraBold.otf);
}

html, body {
    overflow:hidden;
    margin: 0;
    padding: 0;
}

/* Page Piling */
.pp-section {
    height:100%;
    position:absolute;
    width:100%;
}
/* Other styles... */

/* Navbar */
.navbar {
    width: 80%;
    margin: auto;
    left: 0;
    right: 0;
    height: 150px;
    position: fixed;
    z-index: 999;
}

/* Section styling... */

Answer №1

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>pagePiling.js plugin</title>

    <meta name="Resource-type" content="Document" />

    <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Lato:300,400,700" />


    <!--[if IE]>
        <script type="text/javascript">
             var console = { log: function() {} };
        </script>
    <![endif]-->

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

    <script type="text/javascript" src="jquery.pagepiling.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {

            /*
            * Plugin intialization
            */
            $('#pagepiling').pagepiling({
                menu: '#menu',
                anchors: ['page1', 'page2', 'page3', 'page4'],
                sectionsColor: ['white', '#ee005a', '#2C3E50', '#39C'],
                navigation: {
                    'position': 'right',
                    'tooltips': ['Page 1', 'Page 2', 'Page 3', 'Pgae 4']
                },
                afterRender: function(){
                    $('#pp-nav').addClass('custom');
                },
                afterLoad: function(anchorLink, index){
                    if(index>1){
                        $('#pp-nav').removeClass('custom');
                    }else{
                        $('#pp-nav').addClass('custom');
                    }
                }
            });


            /*
            * Internal use of the demo website
            */
            $('#showExamples').click(function(e){
                e.stopPropagation();
                e.preventDefault();
                $('#examplesList').toggle();
            });

            $('html').click(function(){
                $('#examplesList').hide();
            });
        });
    </script>
</head>
<body>
<a href="https://github.com/alvarotrigo/pagePiling.js"></a>

<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://alvarotrigo.com/pagePiling/" data-text="Great plugin to create a single scrolling page pagePiling.js: ">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>

<iframe src="http://ghbtns.com/github-btn.html?user=alvarotrigo&repo=pagePiling.js&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="152" height="20" id="starGithub"></iframe>

    <ul id="menu">
        <li data-menuanchor="page1" class="active"><a href="#page1">Page 1</a></li>
        <li data-menuanchor="page2"><a href="#page2">Page 2</a></li>
        <li data-menuanchor="page3"><a href="#page3">Page 3</a></li>
        <li data-menuanchor="page4"><a href="#page4">Page 4</a></li>
    </ul>


    <div id="pagepiling">
        <div class="section" id="section1">
            <h1>pagePiling.js</h1>
            <p>Create an original scrolling site</p>
            <img src="http://alvarotrigo.com/pagePiling/imgs/pagePiling-plugin.gif" alt="pagePiling" />
            <br />

            <div id="download"><a href="https://github.com/alvarotrigo/pagePiling.js/archive/master.zip">Download</a></div><br />

            <p id="donations">
        <a href="http://vk.cc/35R1HD">
          Donations will be appreciated!</a></p>
        </div>
        <div class="section" id="section2">
            <div class="intro">
                <div id="colors"></div>
                <h1>jQuery plugin</h1>
                <p>Pile your sections one over another and access them scrolling or by URL!</p>
                <div id="markup">

                </div>
            </div>
        </div>
        <div class="section" id="section3">
            <div class="intro">
                <h1>Configurable</h1>
                <p>Plenty of options, methods and callbacks to use.</p>
                <div id="colors2"></div>
                <div id="colors3"></div>
            </div>
        </div>
        <div class="section" id="section4">
            <div class="intro">
                <h1>Compatible</h1>
                <p>Designed to work on tablet and mobile devices.</p>
                <p>Oh! And its compatible with old browsers such as IE 8 or Opera 12!</p>
            </div>
        </div>
    </div>



    <div id="infoMenu">
        <ul>
            <li><a href="https://github.com/alvarotrigo/pagePiling.js/archive/master.zip">Download</a></li>
            <li>
                <a href="http://alvarotrigo.com/pagePiling/" id="showExamples">Examples</a>
                <div id="examplesList">
                    <div class="column">
                        <h3>Navigation</h3>
                        <ul>
                            <li><a href="http://alvarotrigo.com/pagePiling/examples/horizontalScroll.html">Horizontal scroll</a></li>
                            <li><a href="http://alvarotrigo.com/pagePiling/examples/noAnchor.html">Without anchor links (same URL)</a></li>
                            <li><a href="http://alvarotrigo.com/pagePiling/examples/looping.html">Looping</a></li>
                        </ul>
                    </div>

                    <div class="column">
                        <h3>Design</h3>
                        <ul>
                            <li><a href="http://alvarotrigo.com/pagePiling/examples/backgrounds.html">Full backgrounds</a></li>
                            <li><a href="http://alvarotrigo.com/pagePiling/examples/videoBackground.html">Full background videos</a></li>
                        </ul>
                    </div>

                    <div class="column">
                        <h3>Callbacks</h3>
                        <ul>
                            <li><a href="http://alvarotrigo.com/pagePiling/examples/callbacks.html">Callbacks</a></li>
                        </ul>
                    </div>
                </div>

            </li>
            <li><a href="https://github.com/alvarotrigo/pagePiling.js#pagepilingjs">Documentation</a></li>
            <li><a href="http://alvarotrigo.com/#contact-page">Contact</a></li>
        </ul>
    </div>

</body>

*JS**

1
/* ===========================================================
2
 * pagepiling.js 0.0.8 (Beta)
3
 *
4
 * https://github.com/alvarotrigo/pagePiling.js
5
 * MIT licensed
6
 *
7
 * Copyright (C) 2014 alvarotrigo.com - A project by Alvaro Trigo
8
 *
9
 * ========================================================== */
10
​
11
(function(b){b.fn.pagepiling=function(c){function A(a){var c=b(".pp-section.active").index(".pp-section");a=a.index(".pp-section");return c>a?"up":"down"}function g(a,f){var d={destination:a,animated:f,activeSection:b(".pp-section.active"),anchorLink:a.data("anchor"),sectionIndex:a.index(".pp-section"),toMove:a,yMovement:A(a),leavingSection:b(".pp-section.active").index(".pp-section")+1};d.activeSection.is(a)||("undefined"===typeof d.animated&&(d.animated=!0),"undefined"!==typeof d.anchorLink&&c.anchors.length&am...
....
28
"#pp-nav a",function(a){a.preventDefault();a=b(this).parent().index();g(b(".pp-section").eq(a))});b(document).on({mouseenter:function(){var a=b(this).data("tooltip");b('<div class="pp-tooltip '+c.navigation.position+'">'+a+"</div>").hide().appendTo(b(this)).fadeIn(200)},mouseleave:function(){b(this).find(".pp-tooltip").fadeOut(200,function(){b(this).remove()})}},"#pp-nav li")}})(jQuery);

Please check this link:-http://codepen.io/blossk/pen/aFbIo

Answer №2

Don't forget to include the JavaScript code that works its magic!

Just like in the CodePen example you provided:

function switchLogos () {
  $('.altLogo').each(function() {
    $(this).css('top',
      $('.startLogo').offset().top -  $(this).closest('.row').offset().top
    );
  });
};

$(document).scroll(function() {switchLogos();});

switchLogos();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

After clicking the submit button, make sure to automatically fill in all empty input fields

I am currently working on a form that includes various input types such as text fields, radio buttons, select dropdowns, and text areas. The form is displayed in a table format with an option to add additional rows. One issue I have encountered is that us ...

What is the best way to extract an object from an array that only includes one element, and that element is an object?

Here is the output of my updated function: db.collection('SOCIAL').get().then((snapshot) =>{ snapshot.docs.forEach(doc => { tempData.push(doc.data()) }) return tempData }) I want to store these valu ...

How to vertically align text and image in QML Text by utilizing HTML tags with specified height and width dimensions

Here is the QML code snippet that I have been working with. What I have noticed is that when I specify both width and height for the image, it does not align vertically with the text. However, when I remove the specifications of height and width, they ar ...

Discover the steps to execute a continuous loop of animations on a singular component using framer-motion

I'm currently working on a website that incorporates framer-motion for animations One key component of the site is an image displayed as follows: <motion.img ref={scope} initial={{ x: -200 }} alt="pa ...

Guide to retrieving environment variables within React/Node.js applications running in Kubernetes pods

While setting environment variables in Kubernetes pods, I encountered an issue when trying to access them in either Node.js or React front-end code using process.env.TEST (where TEST is present in the environment as secrets), as it always returned undefine ...

Is it possible to manually activate a dropdown event using pure JavaScript?

I am attempting to manually trigger a dropdown event using JavaScript. Below is the function where I am trying to achieve this. I have successfully halted the initial event that occurs and now I need to initiate a dropdown event. stopNavigationTriggerDrop ...

Enhance communication system by optimizing MySQL, JavaScript, and PHP chat functionality

I have created a chat application using Javascript, PHP, and MySQL for two users. Every 3 seconds, it makes an AJAX request to a PHP file to retrieve messages from the database and update the page. Currently, the PHP query used is: SELECT * FROM tmessages ...

Is it possible to modify the text displayed under your website when you search for it online?

I recently developed a website using HTML, CSS, and Javascript. Whenever I search for it on the internet, there is always a text paragraph displayed below its name in the search results. A similar example can be seen in the image here for Facebook. Is th ...

What is the best way to convert exponential values to decimals when parsing JSON data?

var value = '{"total":2.47E-7}' var result = JSON.parse(value); Looking to convert an exponential value into decimal using JavaScript - any suggestions? ...

Using JQuery to locate radio buttons that have been selected based on a variable

In my JavaScript code, I have created a variable called "thisRadio" to represent a dynamically generated div containing multiple radio buttons. Currently, one of these radio buttons may be checked and my goal is to find the checked radio button within this ...

Submitting content to numerous webpages

I'm looking to submit form data on multiple pages, while keeping the main action as "". After clicking, I want the page to refresh but also send the POST data to another .php file. This is necessary because the other .php file generates a graph that ...

Navigating with a Stuck Navigation Bar Using BootstrapretaF

My website has a sticky navbar with a dropdown menu that allows users to jump to different sections of the page. However, I've noticed that when I navigate to a new section, the navbar covers part of the content at the top. After inspecting the navbar ...

What impact does reducing the window size have on my header?

While working on a website with a navigation bar, I encountered an issue where the navbar was not responsive. When the window size was reduced, the nav bar shifted to an awkward position vertically, as shown in the first image. The navbar shifts below the ...

IItemTransform and minified files that are already in use

Summary: IItemTransform is not triggered when a minified file already exists in the same directory as the original (non-minified) file. Issue Description The problem arises due to CSS relative image references, impacting both JavaScript and CSS files when ...

What are the most optimal configurations for tsconfig.json in conjunction with node.js modules?

Presently, I have 2 files located in "./src": index.ts and setConfig.ts. Both of these files import 'fs' and 'path' as follows: const fs = require('fs'); const path = require('path'); ...and this is causing TypeScr ...

finding the ID of the element that triggered a jQuery dialog

I'm utilizing jQuery dialog to trigger popup windows when buttons are clicked. <script> $(document).ready(function(){ $("#dialog-form").dialog({ autoOpen : false, height : 300, ...

Incorporating CSS styles into a dynamic JavaScript computation

I'm attempting to apply inline CSS to a JS calculation (e.g. 3*2*1) in order to make it appear red. I have experimented with using a span tag, but it only displays the calculation and not the result. I also tried utilizing an internal style sheet. Ho ...

Display a Vue.js div element based on conditions matching a specific variable value

Is it possible for Vue.js to display a div only when a defined variable is set to a specific value? Currently, v-show="variable" can be used to show the div if the variable is set. However, I would like to know if v-show="variable=5" can be implemented t ...

Efficient initialization process in Vue.js components

Upon initialization of a component, the data callback is executed as follows: data(){ return { name: myNameGetter(), age: myAgeGetter(), // etc... } }, Following that, a notification is sent to a parent component regarding ...

Tips for automatically focusing a div upon page load

Here is a code snippet for you to review: <div id="details"> <nav> <a href="#1"><span>Summary</span></a> <a href="#2"><span>Perso ...