Animate the movement of a div

Within the given code snippet, the .logo element is initially hidden. The goal is to make it visible upon scrolling, while simultaneously animating the movement of the <ul> element to the right (e.g., sliding). Upon reviewing the demo provided, one can observe that when the logo appears or disappears, the <ul> transitions in a rather abrupt manner. The desired outcome is to achieve a smoother animation for this transition.

How can this objective be accomplished?

HTML:

<div class="header">
    <div class="logo"><img src="http://i.imgur.com/C0ZR4RK.png" /></div>
    <ul class="list">
        <li>Lorem ipsum</li>
        <li>dolor sit amet</li>
        <li>consectetur.</li>
    </ul>
</div>

jQuery:

$(function() {
    var shrinkHeader = 300;
    $(".logo").hide();
    $(window).scroll(function() {
        var scroll = getCurrentScroll();
        if (scroll >= shrinkHeader) {
            $('.header').addClass('shrink');
            $(".logo").fadeIn("slow");
        } else {
            $('.header').removeClass('shrink');
            $(".logo").fadeOut("slow");
        }
    });

    function getCurrentScroll() {
        return window.pageYOffset || document.documentElement.scrollTop;
    }

});

Demo: http://jsfiddle.net/ztdr68aw/

Answer №1

To animate your text, utilize the absolute positioning method. Set the initial position and the destination position for the animation:

            ul {
                list-style: none;
                font-size: 22px;
                position:absolute;
                top:5px;
                left:10px;
                transition:all .3s;
            }

            .shrink ul{
                left:200px;
                top:10px;
            }

See it in action: Fiddle

Answer №3

Here is a helpful solution for you. Appreciate it!

 $(function(){
 var shrinkHeader = 300;
    $( ".brand" ).hide();
  $(window).scroll(function() {
    var scroll = getCurrentScroll();
      if ( scroll >= shrinkHeader ) {                                
          $('.top-bar').addClass('minimize');
          $( ".brand" ).show();
        }
        else {
            $('.top-bar').removeClass('minimize');
            $( ".brand" ).hide();
        }
  });

function getCurrentScroll() {
    return window.pageYOffset || document.documentElement.scrollTop;
    }

});

Answer №4

Follow this Code Snippet

ul {
            list-style: none;
            font-size: 18px;
            position:relative;
            top:3px;
            left:8px;
            -webkit-transition: all 0.3s ease-in-out;
            -moz-transition: all 0.3s ease-in-out;
            -ms-transition: all 0.3s ease-in-out;
             -o-transition: all 0.3s ease-in-out;
              transition: all 0.3s ease-in-out;
        }

        .shrink ul{
            left:180px;
            top:8px;
        }

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

Adaptive Images with jQuery Mobile Listview

I have been experimenting with the classic listview example featuring thumbnails from the jquery mobile documentation. However, when I upload images of different sizes, they do not display properly due to resolution issues. How can this be resolved? Here ...

Implementing Entity addition to a Data Source post initialization in TypeORM

The original entity is defined as shown below: import { Entity, PrimaryGeneratedColumn} from "typeorm" @Entity() export class Product { @PrimaryGeneratedColumn() id: number The DataSource is initialized with the following code: import ...

jQuery sliding toggle effect combining multiple div sets

I have two columns, A & B. Some items in A open multiple items in B. A will toggle its corresponding B Items - BUT clicking on an A that includes an already opened B starts to mess up the toggle. I want each item in A to open its respective items in ...

Develop a custom JavaScript code block in Selenium WebDriver using Java

Recently, I came across a JavaScript code snippet that I executed in the Chrome console to calculate the sum of values in a specific column of a web table: var iRow = document.getElementById("DataTable").rows.length var sum = 0 var column = 5 for (i=1; i& ...

Show the correct URL address in the browser's address bar

My website utilizes Jquery/Ajax to dynamically load html pages into a specific div. By clicking on links with a certain class, the content opens up in this designated div, while the URL displayed in the address bar remains www.example.com. This setup allow ...

What is the most effective way to import and load three-orbitcontrols?

Has anyone tried implementing the OrbitControls function in conjunction with ReactJS? I have included a snippet of the code below: import React, { Component } from 'react'; import 'tachyons'; import * as THREE from 'react'; im ...

A straightforward redirection in Express involving a static file

Just starting out with Node and Express and encountering a bit of trouble. I have a static html page where users enter their username via ajax to my server, and then I want to redirect them to another html file. const express = require("express"); const b ...

What is the purpose of using defer="defer" in JavaScript?

I've been experimenting with Three.js and found that it only functions properly when used like this: <script src="script.js" defer="defer"></script> However, I'm puzzled as to why the defer="defer" attribute is crucial... Can anyon ...

THREE.js: dual scenes sharing identical camera positions

I'm currently working on a project where I have two overlapping scenes. The top scene can be faded in and out using a slider, and users can rotate objects within the scene for a better view. My challenge is to keep the camera position consistent betw ...

Learn the steps for generating an array of objects in AngularJS or JavaScript

I have an array named $scope.data2 and I am looking to create another array of arrays based on the data provided below: $scope.data2 = [ {"dt":"07 Jul 2015","avgdelay":"10","code_sent_time":"07 Jul 2015 12:30 PM" ...

Learn how to configure and utilize an AngularJS factory using ngResource along with passing parameters in the call

As a newcomer to Angular, I'm seeking guidance on creating a new factory utilizing ngResource instead of $http, with the ability to pass parameters. Following an example provided here, I have defined my factory as shown below: app.factory('abst ...

Steps to disable ajax global setting when making an ajax call in a kendo grid

When working with MVC 5 in the _layout page, I have incorporated .ajaxStart and .ajaxStop events to display a busy indicator. <body> <script type="text/javascript"> $(document).ajaxStart(function (e) { $( ...

Deleting a product category along with all its products: Understanding the basics of CRUD操作

I am looking for a way to delete a product category along with all the products within it. The Product model has a reference to the category as an object. Is there a straightforward method or a commonly used technique for this? I attempted to use removeAl ...

What is the process of transferring information from an AngularJS factory to a controller?

I am trying to access raw data object from an angularJS factory that serves as a dataSource for a kendo grid. Despite being able to console log the data in the factory, I'm facing difficulty populating the data object in the controller. How can I retr ...

Achieve sliding animations with Pure CSS using slideUp and slideDown techniques

Currently, I have implemented a code snippet to showcase a menu along with displaying submenus upon hovering over the main menus. Now, I am looking to introduce some animation effects for the submenus when they appear, similar to the slideUp and slideDown ...

What is the best way to determine if an array of objects in JavaScript contains a specific object?

Here is some code that I am working with: let users = []; users.push({ username: "admin", password: "admin" }); this.showAllUsers = function() { console.log(users); }; this.addUser = function(user) { if('username' in user && ...

Retrieve information from the Next API within the getStaticProps function in a Next.js project

In my Next.js project, I encountered an issue where fetching data in getStaticProps() worked perfectly during local development but resulted in an error during next build. The error indicated that the server was not available while executing next build. Fe ...

Testing ng-content in Angular 2

Is there a way to test the functionality of ng-content without the need to create a host element? For instance, let's say we have an alert component - @Component({ selector: 'app-alert', template: ` <div> <ng-conten ...

Dynamic Search Feature Using AJAX on Key Press

Currently, I have developed an AJAX search function that retrieves keyword values upon key up and triggers the script. The objective is to update the content area with results in alphabetical order as the user types each key. However, the issue I am facin ...

Chapter 5 of Eloquent JavaScript's 3rd Edition presents Exercise 3

I'm struggling with an exercise in the latest edition of a book, specifically in Chapter 5 which covers Higher-Order Functions. The prompt for the exercise is as follows: "Similar to the some method, arrays also contain an every method. This method r ...