Revealing CSS elements moving from the left to the right

On my website, I have implemented two different menu bars. The first one, in black, stays fixed at the top of the page. The second one, in orange, becomes sticky once it reaches the black bar. At the same time, a small logo image is revealed, previously hidden using the "inactive" class with "display: none". It then appears by removing the "inactive" class and adding the "active" class with "display: inline-block".

View the animated gif here:

Check out the live version here:

However, the transition from "display: none" to "display: inline-block" is quite sudden. I need assistance in creating a smoother transition where the logo is revealed from left to right, gently pushing the social icons to the right.

Below is the code snippet:

HTML

<div class="topbar-container">
    <div id="slc" class="notonmobile scroll-logo inactive">
        <a href="http://mydivision.net/" title="MYDIVISION.NET | Home">
            <img src="http://mydivision.net/wp-content/themes/v1/img/scroll-logo-small.png" alt="Logo" />
        </a>
    </div>
    <div id="social_container">
        ...
    </div>
    ...
</div>
</div>

CSS

#topbar {display: inline-block; width: 100%; padding: 0; height: 40px; background: #000; position: fixed; top: 0; z-index: 9999;}
.topbar-container {margin: 6px 20px; line-height: 24px;}
.scroll-logo.inactive {display: none;}
.scroll-logo.active {display: inline-block; float: left; margin-right: 20px;}
.scroll-logo img {height: 24px; padding: 3px 0;}
#social_container {float: left; width: 192px;}

jQuery

jQuery(document).ready(function($) {
    $(window).scroll(function() {
        if ($(this).scrollTop() >= $('.sticky-element-active').offset().top - 40) {
            $("#slc").addClass("active");
            $("#slc").removeClass("inactive");
        } else {
            $("#slc").removeClass("active");
            $("#slc").addClass("inactive");
        }
    });
});

Answer №1

After making some adjustments to your live CSS, I was fortunate enough to see some positive results. Feel free to experiment with the transition times and make further tweaks if needed. Hopefully, this will guide you in the right direction.

.modified-logo.inactive {
  transition: 0.7s;
  transform: translateX(-80%);
  opacity: 0.2;
  height: 10%;
}

.modified-logo.active {
  transition: 0.5s;
  transform: translateX(20px);
  opacity: 0.9;
  float: left;
  margin-right: 30px;
}

https://i.stack.imgur.com/5W1UO.gif

Answer №2

Replace the usage of active and inactive classes in your CSS with the code provided below. Using Jquery's show() and hide() functions will cause elements to expand and contract when a duration is set for them.

However, ensure that you still have the inactive class specified in your HTML so that the expansion only occurs once each time the scroll condition is met:

jQuery(document).ready(function($) {
    $(window).scroll(function() {
        if ($(this).scrollTop() >= $('.sticky-element-active').offset().top - 40 && $("#slc").hasClass("inactive")) {
            $("#slc").show(1000);
            $("#slc").removeClass("inactive");
        } else {
            $("#slc").hide(1000);
            $("#slc").addClass("inactive");
        }
    });
});

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

Get rid of all the formatting on an HTML button or submit

Is there a method to entirely eliminate the styling of a button in Internet Explorer? I am utilizing a CSS sprite for my button and everything appears fine. However, when I click on the button, it shifts slightly upwards which distorts its appearance. Are ...

What is causing the slider image to be the only element that is not adapting to different screen sizes?

I am currently using the flexslider from woothemes and I am unable to understand why the image is consistently wider than the content when the browser window is resized or when viewed on an iPad/iPhone. Upon inspection, I couldn't find any styles on ...

Having trouble displaying all 6 columns in the Bootstrap carousel - only 3 columns are showing up

I came across this inspiring Codepen and decided to tweak it to support Bootstrap's col-md-2 class. Despite my efforts, only 3 columns are showing up. I suspect that neighboring cards of the active card receive additional classes for display purposes ...

Ruby on Rails slider bar functionality

Currently, I am developing a video-focused application using Ruby 1.9.2 and Rails 3.1. One of the key features I need to implement is a slider bar that allows users to adjust the total duration of a video in real-time. Despite my attempts to use HTML5 fo ...

Is it possible to assign a specific value to a row within a table?

For each row (tr) generated from my database, I would like to assign a unique row value. Let's consider the table being created: while ($row = $database->fetch_array($result)) { $i=1-$i; $class = "row".$i; echo "<tr class='{$class} produ ...

Guide on How to Show Only the Initial Word of an H2 Header Using JavaScript or CSS

Is there a way to display only the first word from an h2 heading? For instance: In the website's source code, it would appear like this <h2> Stackoverflow is an Ideal Place</h2> But on the live website, it should be displayed like this ...

The Everyday Explanation of Same Origin Policy

Could anyone simplify the concept of the Same Origin Policy for me? I've come across various explanations but I'm in search of one that a child can easily understand. I found this link to be quite helpful. Is there anyone who can provide further ...

What are the steps to limit the usage of angular.module('myApp', ['ngGrid', 'ui.bootstrap', 'kendo.directives'])?

I have two JavaScript files with AngularJS code. The first file, myjs1.js, includes the module: angular.module('myApp', [ 'ngGrid', 'ui.bootstrap', 'kendo.directives' ]); The second file, myjs2.js, also includes th ...

Leveraging PHP's PDO with MySQL in combination with the power of JQuery

Hey there, I'm dealing with a login form that includes fields for both username and password. I have a PHP backend script that properly processes the data and encodes the response in JSON format. However, my JQuery JS script utilizing Ajax doesn&apo ...

Unable to trigger a click on the submit button using JavaScript

I'm encountering difficulties in triggering a click using JavaScript on a Mailchimp pop-up subscribe form and I require your assistance. <!-- Title & Description - Holds HTML from CK editor --> <div class="content__titleDescripti ...

Chrome not recognizing Jquery form select option

Hello, I am new to using Jquery and facing an issue with the following scenario: I am trying to create a form select tree where selecting one option triggers another select box to appear. The code works perfectly in Firefox and Internet Explorer, but seem ...

Validating radio buttons in Ionic framework

I am currently working on implementing a form in my application using Ionic and AngularJS. I have added validation to all the fields, but I am facing an issue with the radio button validation. The error message is being displayed correctly when no radio bu ...

Is there a way to adjust the height relative to the viewport in Bootstrap 5 for values other than 100?

Attempting to create a new type of div using a custom stylesheet with minimal non-bootstrap css. I am trying to convert each style rule from my django static files CSS into a bootstrap class, but I am stuck on viewport-based sizing. Prior to discovering t ...

Help me figure out how to independently toggle submenus on my navbar by utilizing the Vue.js composition API

I am currently working on developing a navbar using the Vue.js composition API. My primary objective is to toggle the submenus when a user clicks on them. However, since I am iterating through an object to display the submenus, I am faced with the challeng ...

remove all clicks from jQuery queue

I am facing an issue with a click event that triggers other click events, resulting in the addition of elements to the DOM. EDIT: However, upon clicking it multiple times, additional elements are added each time. Checking the jQuery queue confirms that an ...

The dynamic data is not displaying on the Chart bundle JavaScript

I am currently utilizing chart bundle js for my project. While everything appears to be functioning properly on alter show, I am encountering an issue with the map display – nothing is showing up as intended. If anyone has a solution to resolve this iss ...

What is the best way to locate a table of a specific class using jQuery selectors?

Is there a way to specifically target a table with the class "d" using jQuery selectors? I'm having trouble making it work... var dTableTags = $(".d table"); For instance, an example table would look like this... <table id="thetable" class="d"&g ...

Changing an HTML container using jQuery and Ajax to facilitate a login process

Currently, I am on the lookout for a unique jQuery plugin that can replace a div when a successful login occurs. Despite searching multiple times on Google, I have been unable to find an ideal plugin that meets my specific needs. Do any of you happen to kn ...

Parse JSON data, iterate through dictionaries, and convert into markup using Python

I'm working with a JSON file that contains information about different people: { "PersonA": { "Name": "Woman A", "Age": 23, "Info": "Likes cats ..." }, "PersonB": { "Name": "Man B", "Age": 32, ...

Notify of a specific value in an array that is retrieved through an AJAX request

I'm currently facing an issue with trying to display the value obtained from an ajax call. The code snippet below is functional in such a way that it will successfully alert the value of 'row' when grid.onClick is triggered. However, I am st ...