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

What is the best way to capitalize the first letter of a string in JavaScript?

Is there a way to capitalize only the first letter of a string if it's a letter, without changing the case of any other letters? For example: "this is a test" → "This is a test" "the Eiffel Tower" → "The Eiffel ...

How can I delete the header and footer on a personalized homepage design?

After crafting a unique home page/landing page for my website that stands out from the rest, I've come across an issue. The header and footer are appearing on this new page, but I only want to display what I specifically coded. I attempted using Site ...

Understanding special characters within a URL

Here is a URL example: postgres://someuser:pas#%w#@rd-some-db.cgosdsd8op.us-east-1.rds.amazonaws.com:5432 This URL is being parsed using the following code snippet: const url = require('url'); const { hostname: host, port, auth, path } = url.par ...

Using infoWindows with multiple markers in Google Maps

i have developed a custom Google Maps application that pulls data from a CSV file. The functionality works well, but I am facing an issue with the infoWindow when looping through all the objects. It seems like the problem stems from the marker variable bei ...

What is the best way to manage multiple form submissions on a single page using Ajax and PHP?

I am currently working on creating an admin panel with two forms on the same page, both being handled using Ajax and PHP. Although I have written the necessary code, I am facing an issue where the data is not getting saved in the database. Data_entry.php ...

I am looking to incorporate a 10 px border at the top of my column by utilizing bootstrap4

How can I add a border to the top of my column using Bootstrap 4? I've been struggling with it and can't seem to get it right. Here is the code I'm currently using, which includes <div> tags for the columns: <!doctype html> &l ...

Implementing a node.js application deployment with pm2 to ensure zero downtime

While there are countless tutorials on developing chat applications using socket.io and node.js, the event-driven advantage of Node is undeniable for building chat apps. However, a recent thought crossed my mind - how can I ensure the sustainability of my ...

Ways to retrieve row and column data from a datagrid

Below is the code snippet I am currently working with: import React from 'react' import Button from '@material-ui/core/Button'; import Checkbox from '@material-ui/core/Checkbox'; import { DataGrid } from '@material-ui/da ...

problem with passing the identification number into the function

I am facing an issue with passing the id into a javascript onClick method. I am using the Spring framework and in the controller class, I send the related id to the JSP file like this: model.addAttribute("uploadid", uploadid); Afterwards, I need to p ...

Is it possible to refresh only a specific table on a Razor site without reloading the entire page?

Greetings! I am currently working on a table and facing an issue. Currently, I am unable to update the table without the website refreshing. I require a solution that will allow me to easily Add, Delete, or Modify rows in the table's content. This ...

The background image is not displaying correctly in the tag td

I'm struggling to display a background image inside a table data cell using CSS. <td class='details-control'></td> When I use the following CSS rules, the image is not displayed: td.details-control { background: url(http:// ...

React Native: Avoiding Infinite Loops in useEffect

I am facing an issue where my app goes into an infinite loop because pointsData is inside the useEffect function. How can I resolve this situation? function useGetPoints() { const [pointsData, setPointsData] = useState<PointTbleType[]>([]); ...

Creating a dynamic hover drop-down navigation bar in ASP.NET

After successfully creating a navigation bar with hover effects, I am now looking to implement a dropdown list when hovering over the items. Can anyone provide guidance on how to achieve this? Below is the current code snippet I am working with: <ul c ...

Executing file upload in parent component with Angular 2

Is there a way to initiate a file upload from the parent component of the router? Specifically, I need to execute two functions located in the parent component - openFileSelect and uploadSelectedFile to manage the <input type="file"> element. This i ...

javascript function not being invoked

Currently, I have incorporated the following HTML <html> <head> <Title>EBAY Search</title> </head> <script language="JavaScript" src="ajaxlib.js"></script> <body> Click here & ...

Iterating through an array with ngFor to display each item based on its index

I'm working with an ngFor loop that iterates through a list of objects known as configs and displays data for each object. In addition to the configs list, I have an array in my TypeScript file that I want to include in the display. This array always ...

What is the best way to use jQuery AJAX to make changes to an HTML element that will be permanent even after the page is refreshed?

Starting out with codeigniter, I am working on building an ecommerce website. Every time a user clicks the "Add to cart" button in my view, I utilize jquery ajax to send a request to a controller function. This function then returns two variables: count ( ...

Issue with Angular Bootstrap Modal autofocus functionality malfunctioning

I successfully integrated a bootstrap modal using angular bootstrap into my project. If you want to check out the code I used, here is the plunker link. Inside the modal, there is only one input field (textbox) that the user needs to fill, along with sav ...

How can an Embedded React + JSS component safeguard generic elements such as <button> and <p> from being affected by the page's style?

I am facing a challenge with a React component that is being embedded in various webpages, either through an extension or as a third-party tool. Most of the styling for this component is done using JSS, ensuring unique class names that cannot be overridde ...

AngularJS ng-repeat is not updating when the state changes

Seeking assistance with an Angular application challenge I'm facing. I have implemented a ng-repeat in my app to display the latest messages stored in an array within a controller named "comunicacion": ng-repeat in comunicacion.html <div class=" ...