Adjust the size of the logo as the user scrolls

Currently, I am implementing a JavaScript feature that allows my logo to shrink when the user scrolls down and grow when they scroll up.

To achieve this effect, I am utilizing the jQuery functions addClass and removeClass.

However, I have encountered some issues along the way.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
 $(function(){
      var navStatesInPixelHeight = [65,90];

      var changeNavState = function(nav, newStateIndex) {
        nav.data('state', newStateIndex).stop().animate({
          height : navStatesInPixelHeight[newStateIndex] + 'px'
        }, 600);
      };

      var boolToStateIndex = function(bool) {
        return bool * 1;    
      };

      var maybeChangeNavState = function(nav, condState) {
        var navState = nav.data('state');
        if (navState === condState) {
          changeNavState(nav, boolToStateIndex(!navState));
        }
      };

      $('.top_nav').data('state', 1);

      $(window).scroll(function(){
        var $nav = $('.top_nav');

        if ($(document).scrollTop() > 0) {
          $('.contact_details').hide();
          $nav.addClass('fixed-nav');
          $('.top_nav').css('background-color','rgba(33,33,33,1.0)');
          maybeChangeNavState($nav, 1);
        } else {
          $('.contact_details').show();
          $nav.removeClass('fixed-nav');
          $('.top_nav').css('background-color','rgba(0,0,0,.5)');
          maybeChangeNavState($nav, 0);
        }
      });
    });

    <header>
        <div class="top_nav">
        <div class="logo">
            <a id="site-logo" href="#"><img src="http://www.robinwhale.co.uk/pages/wisdom/sigs_files/google-logo.jpg" alt="LOGO"></a>
            </div>
            <div class="contact_details">
                <p>Need Help, Call: +92 445676654 |<a href="#"> Mail</a></p>
            </div>
            <div class="nav_bar">
                <ul>
                    <li><a href="#">Services</a></li>
                    <li><a href="#">Solution</a></li>
                    <li><a href="#">Support</a></li>
                    <li><a href="#">Partners</a></li>
                    <li><a href="#">Contacts</a></li>
                </ul>
            </div>
        </div>
    </header>
    <div class="container">
    </div>

    *{
        margin: 0;
        padding: 0;
    }

    /* Top Menu Start Here */

    .top_nav{
        height: 90px;
        width: 100%;
        background: rgba(0,0,0,.5);
        position: fixed;
        transition:all 0.7s ease;
        -webkit-transition:all 0.7s ease;
        -moz-transition:all 0.7s ease;
        -o-transition:all 0.7s ease;
        -ms-transition:all 0.7s ease;
    }

    .top_nav .logo{
        margin-top: 2px;
        margin-left: 20px;
        height: 75px;
        width: 200px;
        float: left;
        transition:all 0.7s ease;
        -webkit-transition:all 0.7s ease;
        -moz-transition:all 0.7s ease;
        -o-transition:all 0.7s ease;
        -ms-transition:all 0.7s ease
    }

... (The remaining code has been omitted for brevity) ...

Answer №1

Make changes to your CSS

You need to adjust the height of the logo on the fixed navigation bar

 .top_nav .logo{
    margin-top: 2px;
    margin-left: 20px;
    height: 75px;
    width: 200px;
    float: left;

    /* Remove transitions from this section */
    /* 
    transition:all 0.7s ease;
    -webkit-transition:all 0.7s ease;
    -moz-transition:all 0.7s ease;
    -o-transition:all 0.7s ease;
    -ms-transition:all 0.7s ease;
    */
}

.top_nav .logo a img {
    transition: all 0.9s ease 0.7s;
}

.fixed-nav .logo img {
    height: 80% !important;
}

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

Refreshing dynamically added rows through ajax updates

I'm struggling to clearly articulate my problem. Currently, I have a function that retrieves values from a database using ajax and then dynamically adds each result as a row in a table. This allows users to edit or delete any row as needed. I'm ...

Customized Bootstrap Dropdown with the ability to add text dynamically

I am working on a Bootstrap dropdown menu that allows users to generate expressions by clicking on the menu items. For example, when the "Action" item is clicked, it should insert {{Action}} into the textbox. The user can then type something like "Hello" a ...

Accessing Form Data as an Array in a Single Page Application

I'm currently in the process of developing a single-page PHP application and I'm experimenting with submitting the form using ajax .post() instead of the traditional form submission that redirects to another page. However, I'm experiencing d ...

How can I vertically align text in React-bootstrap Navbar Nav-items?

I have been struggling to find a solution to my problem without resorting to custom CSS classes. I'm wondering if it's possible to achieve what I need using only flex classes. Here is the code for a simple navbar component: <Navbar bg ...

Capture a screenshot of an embedded object and include it in an email using the mailto function

Is there a way to capture a screenshot of a flash object on a webpage and then send it via email using a mailto: form submission to a designated address? I have attempted to use different JavaScript techniques, but none seem to be successful. Appreciate a ...

Combine the promises from multiple Promise.all calls by chaining them together using the array returned from

I've embarked on creating my very own blogging platform using node. The code I currently have in place performs the following tasks: It scans through various folders to read `.md` files, where each folder corresponds to a top-level category. The dat ...

Issue with switching button and content positioned absolutely

Within this container, I have some content followed by a slide toggle button and then more content. The toggle button utilizes the jQuery function slideToggle. All elements within are positioned absolutely. [Introduction Content] Toggle Button [Hidden C ...

Can Datatables be incorporated with modal pop-ups for editing purposes?

I am dealing with a DataTable that fetches data from a remote server. Each cell in the table has a mouse-over link that can trigger a modal popup (all links are the same). The issue I'm facing is the inability to pass the unique ID of the row and the ...

I am having difficulty toggling text within a for loop in JavaScript

When I display a list of cards using a for loop and click on them, I want to toggle some text. The issue I'm facing is that it works fine for the top card, but when I click on the card below, it toggles the text of the first card instead. This is desp ...

Maximizing the impact: tips for utilizing URL links effectively

I am currently utilizing the supersized feature from this source. Could someone guide me on how to utilize the URL of a slide? I have already made use of the title and understand that I need a div slidecaption with an ID, but how do I include a slide URL ...

Can an AJAX upload progress bar be implemented in Internet Explorer without using Flash?

I've been searching for solutions to upload files without using flash, but all of them either require flash or lack a progress bar on IE (7-8). I couldn't find any mention of an "progress" event in the MSDN documentation for XMLHTTPRequest. Is i ...

Struggling with PHP variables and AJAX JavaScript

Hey everyone, I've made some edits and have a new question regarding a similar issue. On test.php in my Apache server, I have a PHP script that connects to a database and retrieves data from a table. <?php $con = mysqli_connect("localhost", "user" ...

Whenever the page is refreshed, the vertical menu bar with an accordion feature hides the sub

I have designed a vertical accordion menu bar following the example at http://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_accordion_symbol However, I am encountering an issue where clicking on a button to display a submenu causes the page to refr ...

Display sqllite database information in an HTML view using Ionic 2

After executing a select query against the database, I am able to read the results from the logcat and view the data there. However, I am encountering an issue where the data is not rendering in the HTML view after binding. //data retrieve section db.exec ...

Challenges with altering the height of a div through animation

HTML <div class="blok1" ></div> <div class="blok2"></div> <div class="blok3"></div> CSS .blok1 { background-color: green; border-bottom-left-radius:15px; border-bottom-right-radius:15px; h ...

Swap the Text for a Button

I've been searching for a solution to this problem, but all I seem to find online is advice on how to "replace button text." What I'm trying to achieve is to have text change into a button when hovered over. I've attempted using fadeIn/fade ...

Grouping of check-boxes in sets of 3

I need to customize the display of my checkboxes by grouping them side by side. Instead of showing them in a list format, I want them to be displayed in groups. For example, when there are 7 checkboxes, I would like them to be split into two columns with ...

Retrieve JSON data using AngularJS

Can someone guide me on how to make a GET request to my API endpoint and handle the JSON response in my code? Sample Controller.js Code: oknok.controller('listagemController', function ($scope, $http) { $scope.init = function () { ...

Trying to incorporate a PHP echo statement into the innerHTML of a button is ineffective

I have a piece of jQuery code that is not functioning as expected: $("#erase").click(function(){ $("#erase").attr("disabled", "disabled"); // Prevent double-clicking $(this).html("Erasing..."); $.post("erase.php", {target: $("#targ ...

Unable to insert values into database using PHP

I've put together a user registration form using PHP, jQuery, and SQL. I have everything set up to send the details to the database via an AJAX request. The code is running smoothly without errors, but for some reason, the values are not being added t ...