Is there a way to have the logo effect return to its original state when the user scrolls back up to the top of the page?

Are there any new suggestions for my issue? The previous solutions I received didn't quite work, but I'm grateful for the effort.

I am currently working on a project where logo 1 fades out in the header as logo 2 fades in while scrolling down. However, I would like the header to return to its original state with logo 1 fading back in when the user scrolls back to the top of the page. I have limited knowledge of JavaScript and have tried researching various methods to achieve this effect without causing any errors in my current code. Any assistance is greatly appreciated.

 <header>
                <div id="nav" class="navbar">
                    <div id="nav_left">
                        <a href="index.html">HOME</a>
                        <a href="services.html">SERVICES</a>
                        <a href="portfolio.html">PORTFOLIO</a>
                    </div>
                    <a href="index.html" id="logo" class="Claire_logo">
                        <img src="images/logo_6_small.png" alt="logo2" id="logo_Claire" class="logo_main"
                            style="display:none" />
                        <img src="images/logo_bluebird_90_cc.png" alt="logo1" id="logo_Claire_blue" class="logo" />
                    </a>
                    <div id="nav_right">
                        <a href="blog.html">BLOG</a>
                        <a href="about.html">ABOUT</a>
                        <a href="contact.html">GET IN TOUCH</a>
                    </div>
                </div>
            </header>
    $(document).ready(function() {
      $(window).scroll(function() {
        var scroll = $(window).scrollTop();

        if (scroll > 70) {
          $('#logo_Claire_blue').fadeOut(800);

          setTimeout(function() {
            $('#logo_Claire').fadeIn(800);
          }, 800)
        };
      });
    });

Answer №1

To introduce the else condition, simply switch the fadeIn and fadeOut

$(document).ready(function() {

    $(window).scroll(function() {
      var scroll = $(window).scrollTop();
      if (scroll > 70) {
        $('#logo_Claire_blue').fadeOut(800);
        setTimeout(function() {
          $('#logo_Claire').fadeIn(800);
        }, 800)
      } else {
        $('#logo_Claire_blue').fadeIn(800);
        setTimeout(function() {
          $('#logo_Claire').fadeOut(800);
        }, 800)
      }
    });
});

Update:

In the else condition, you can try this approach

$('#logo_Claire_blue').fadeIn(800);
$('#logo_Claire').fadeOut(800);

Answer №2

 $(document).ready(function() {
                            $(window).scroll(function() {
                                if ($(document).scrollTop() > 8) {
                                    $('nav').addClass('transparent-bg');
                                    $('.img1').show();
                                    $('.img2').hide();
                                } else {
                                    $('nav').removeClass('transparent-bg').css('color: black');
                                    $('.img2').show();
                                    $('.img1').hide();
                                }
                            });
                        });

Answer №3

The code snippet:

<div class="main-content">
<section>
  <div class="primary-logo">Your Brand</div>
</section>
</div>

The Styling:

.main-content {
  height: 2000px;
  position: relative;
}

section {
  position: fixed;
  width: 100%;
  height: 50px;
}

.primary-logo {
  width: 300px;
  height: 50px;
  text-align: center;
  background-image: url('https://website.com/logo.png');
}

.secondary-logo {
  width: 200px;
  height: 20px;
  text-align: center;
  background-image: url('https://website.com/secondary-logo.jpg');
}

The JavaScript Function:

$(function () {
    var logo = $(".primary-logo"); $(window).scroll(function () {
        var scroll = $(window).scrollTop();

        if (scroll >= 500) {
            if (!logo.hasClass("secondary-logo")) {
                logo.hide();
                logo.removeClass('primary-logo').addClass("secondary-logo").fadeIn("slow");
            }
        } else {
            if (!logo.hasClass("primary-logo")) {
                logo.hide();
                logo.removeClass("secondary-logo").addClass('primary-logo').fadeIn("slow");
            }
        }

    });
});

Could you please confirm if this setup is effective? Thank you.

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

Obtaining a background image within a keyframe

I have been experimenting with keyframe animations and am looking to incorporate multiple images into the animation. Specifically, I want to switch out the image every 10% increment to depict someone running. Despite my efforts to use a background-img in ...

The jQuery UI datepicker fails to display if the element has previously been hidden

In the process of creating a wizard, I have designed each step to remain hidden until the user reaches that specific stage. The second step of the form is dynamically generated based on the input provided in the first step. Here is a glimpse of how it all ...

Employing a pair of images for submission in a form

Similar Question: How to change an input button image using CSS? Can I create a form with two image submit buttons? I am working on a language selection page that displays two flags (.png's) and I would like it so that when a user clicks on a fl ...

Navigational Buttons for Forms in Bootstrap Tabs

I am currently working on splitting a form across multiple Bootstrap 3.x tabs. However, I am encountering issues with the functionality of the previous and next buttons. Only the first next button seems to be working correctly, and there are instances wh ...

Retrieve the next 14 days starting from the current date by utilizing Moment.js

Looking to display the next 14 days in a React Native app starting from today's date. For example, if today is Friday the 26th, the list of days should be: 26 - today 27 - Saturday 28 - Sunday 01 - Monday 02 - Tuesday ............ 12 - Friday Is ther ...

Prevent postback from ImageButton OnCommand by utilizing JavaScript in asp.net 4.0 specifically for Internet Explorer

It seems like the Internet Explorer issue has resurfaced, and I'm struggling to resolve it: I have an ImageButton set up with OnCommand to delete a specific entry from my database. However, I've added a confirmation step for the user before dele ...

Unusual AngularJS error encountered while performing calculations on object properties

After running a specific calculation in my code, I encountered an unexpected issue. if (typeof $scope.memoryTable[name][category]['total'] !== 'undefined') { $scope.memoryTable[name][category]['total'] = $scope.memoryTabl ...

Is it possible to incorporate spread syntax(...) within a vue.js 2.x template?

Is it possible to utilize a similar structure in a vue.js template? <template> <vxe-table> <vxe-column v-for="options in someConsts" ...options width="160"> </vxe-column> </vxe-ta ...

Vue components are failing to appear in the live environment, however they function perfectly in the development environment

My Laravel Vue project runs smoothly in development, but on the live shared hosting server, the vue components are not displaying. However, the Laravel views function correctly with no errors in the console. I have already run npm run production to minif ...

What are the drawbacks of relying on a dependent dependency in software development?

In a recent discussion on Stack Overflow, it was suggested that the best practice is to install packages from sub-dependencies for future use in the app, rather than directly from the dependencies node_modules folder. However, my scenario is a bit unique. ...

Lack of coherence in events

Currently, I am learning JS and WebApi.Net. One issue that I am facing is that part_2 is sometimes executed before part_1, even though it should be the other way around. //**** <part_1> **** var link = 'api/Values', ttMass = new Array(); ...

Repair the navigation bar once it reaches the top of the screen using ReactJS

I have a webpage that contains specific content followed by a bar with tabs. My goal is to have this bar stay fixed at the top of the screen once it reaches that position while scrolling down, and only allow the content below the fixed bar to continue scro ...

Utilizing Jquery to Add Elements and Adjust Element Height

Encountering an unusual issue where the height of a div is not updating when content is appended to it using JQuery. To demonstrate the problem, I have created a simple JSFiddle: http://jsfiddle.net/hf66v/5/ Here is the initial HTML structure: <div i ...

JavaScript reasoning based on logic

I am working on a webpage titled a.jsp that contains the following elements: --a1-- --a2-- --a3-- <select onChange="cht('1');" id="a1"><option>H263</option><option>H264</option></select> <div class="Text" ...

Safari failing to display Arc on 2D context

When attempting to draw a simple circle on a canvas, everything works smoothly in Chrome but encounters issues in Safari. What's puzzling is that even though I can retrieve the x position of the circle as expected, it simply fails to render correctly ...

Why isn't my margin: auto code centering correctly?

My current struggle involves centering a div within the document. While I have successfully achieved horizontal centering, vertical centering remains elusive: width: 950px; height: 630px; background: #FFFFFF; margin: auto; Is it not expected that margin: ...

What is the best method for streaming files from Java to the browser while preventing the user from downloading and saving the file?

I'm new to this and feeling a bit lost. Here's the situation: I have a web app (built with JavaScript/Reactjs) and a backend (Java using Liferay API) The server contains files (File A, B, C, etc.) of various types: pdf, excel, audio, txt, etc. ...

Exploring the functions of `map` and `filter` in the world of

Consider this input: var m = [{ name: 'foo', routes: [{verb: 'post', path: '/foo1'}, {verb: 'get', path: '/foo2'}] }, { name: 'bar', routes: [{verb: 'put', path: ...

Is there a decrease in performance when interacting with variables in the method below?

Alright, I have a reference to a div stored in a variable, which I'll refer to as div_var. Now, when I want to apply some action to it, I have two options for referencing it: div_var.animate()...... $(div_var).animate()..... The first method is mor ...

Can anyone suggest a more efficient approach to handling variations using CSS?

Within the message component, there are currently only two variants available: error and success. This project is built using vue3 script setup and utilizes SCSS for styling. <script setup lang="ts"> defineOptions({ name: 'Notificat ...