What could be causing the animation to fail when I attempt to add more than four items to the menu and push it to the left?

Having trouble implementing a left push menu on my website. When trying to add more than 4 sidebar items, they do not follow the animation properly. Only the last item seems to work correctly. How can I resolve this issue?

Click Run code and Full page.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Left Push Menu</title>
<style>
/*@import url(https://fonts.googleapis.com/css?family=roboto); */
body, html {
  height: 100%;
  padding: 0;
  margin: 0;
  font-family: 'roboto', sans-serif;
}
h1 { text-align:center; margin:50px auto; color:#fff;}

main {
  z-index: 2;
  position: relative;
  height: 100%;
  background-color: #2D3142;
  -webkit-transition: transform .7s ease-in-out;
  -moz-transition: transform .7s ease-in-out;
  -ms-transition: transform .7s ease-in-out;
  -o-transition: transform .7s ease-in-out;
  transition: transform .7s ease-in-out;
}

/* rest of the CSS code removed for brevity */

$(document).ready(function() {
  function toggleSidebar() {
    $(".button").toggleClass("active");
    $("main").toggleClass("move-to-right");
    $(".sidebar-item").toggleClass("active");
  }

  $(".button").on("click tap", function() {
    toggleSidebar();
  });

  $(document).keyup(function(e) {
    if (e.keyCode === 27) {
      toggleSidebar();  
    }
  });

});

</script>
</body>
</html>

Answer №1

Apply the specified CSS styling only to the 1st, 2nd, 3rd, and last elements.

.sidebar-item {
  margin: 30px 0;
  opacity: 0;
  -webkit-transform: translateY(20px);
  -moz-transform: translateY(20px);
  -ms-transform: translateY(20px);
  -o-transform: translateY(20px);
  transform: translateY(20px);
  -webkit-transition: all .7s .2s ease-in-out;
  -moz-transition: all .7s .2s ease-in-out;
  -ms-transition: all .7s .2s ease-in-out;
  -o-transition: all .7s .2s ease-in-out;
  transition: all .7s .2s ease-in-out;
}

Simply include the above code and remove everything else.

Answer №2

The specific transition effects are limited to only the designated "child" elements:

.sidebar-item:first-child {
  /*...*/
}

.sidebar-item:nth-child(2) {
  /*...*/
}

.sidebar-item:nth-child(3) {
  /*...*/
}

.sidebar-item:last-child {
  /*...*/
}

If additional elements like nth-child(4), nth-child(5), and so forth exist, they will not inherit any transitions.

To include them, use the following code:

.sidebar-item:nth-child(4) {
  -webkit-transition: all .7s .8s ease-in-out;
  -moz-transition: all .7s .8s ease-in-out;
  -ms-transition: all .7s .8s ease-in-out;
  -o-transition: all .7s .8s ease-in-out;
  transition: all .7s .8s ease-in-out;
}

/* Adjust values as needed for continued elements... */

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 are the specific files I should modify for HTML/CSS in my Ruby application?

My application was initially created with an introduction from: http://guides.rubyonrails.org/getting_started.html I am now looking to add some color and style through CSS. I have located the JavaScript and CSS files, but I am unsure which file is respons ...

Creating a vertical image carousel that accommodates images of varying heights requires strategic coding and logical struct

I am working on developing a vertical jQuery carousel for images sourced from a database. Since I do not know the height of these images, is there a logical way to calculate the height of the container? ...

ng-if not working properly upon scope destruction

While working on a isolate scope directive, I encountered an issue. In the link function of this directive, I am compiling an HTML template and then appending it to the body of the document. const template = `<div ng-if="vm.open"></div>`; body ...

The image in the top left corner is not aligned properly with the menu

How can I ensure that the top left image (logo2.jpg) on my page stays aligned with the menu below it instead of shifting to the right? Here is the link to the page for reference: #logo { margin:0 auto; width: 975px; position:relative; } #top { position ...

Here's a unique version: "Discovering how clients can easily connect to a new room using socketio

There are 5 rooms on my server named "A", "B", "C", "D", and "E." Server-Side In the server side code: io.on('connection', (socket) => { console.log('New user connected'); socket.on('disconnect', () => { ...

Harness the power of the ioHook Node.js global native keyboard and mouse listener within your Browser environment

I'm dealing with a challenging issue that seems to have no solution due to security limitations. However, I'm reaching out to you as my last hope to find a workaround. For my project, I require a system that can monitor user mouse and keyboard a ...

Input drives the radius

I'm curious about creating a map application that can input and display a 3km radius around a specific location. Any guidance would be greatly appreciated. Please excuse my imperfect English (haha). ...

Tips for optimizing a CSS file that includes the @page at-rule

When the CSS file for media='print' contains the @page directive, .myreceipt { @page { visibility: hidden; margin: 0 15px; } @page { height: auto; } } The ASP.NET MVC4 built-in minification tool does not ...

Javascript text validation is malfunctioning as the alert message fails to appear

Looking for a simple form validation script: <script language=”javascript”> function checkForm(register) { if (""==document.forms.register.FNAME.value){ alert("Please fill out this field!"); document.forms.register.FNAME.focus( ...

I'm about to lose my mind because of this JavaScript code - is there a syntax

My code is showing an unexpected token < error, even though all the < signs are correctly placed. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title>Document</title> </head> <body& ...

Is it time to execute a mocha test?

Good day, I am currently exploring the world of software testing and recently installed Mocha. However, I seem to be encountering an issue with running a basic test that involves comparing two numbers. Can someone please guide me on why this is happening a ...

Conditional statement based on the selection of an AJAX checkbox

I have multiple variables retrieved from form IDs that are then sent in a query string to PHP. One of the inputs is a checkbox, and I am attempting to use AJAX to set the variable's value based on whether it is checked or not. For example: if (do ...

Attempting to create a button cluster using Bootstrap and AngularJS for the purpose of navigating to various URLs

Looking to create a pair of buttons using bootstrap and angularjs that will redirect to different URLs when clicked. Here is the relevant code snippet: app.controller('LinkController',function(link, $scope, $location){ $scope.go = function() ...

Modify the background color of a specific bar across multiple charts when hovering or clicking - utilizing chart.js

I have multiple chart.js canvas elements on a webpage. The goal is to be able to quickly identify and highlight the same bar value across all the charts. For example, when I hover over a bar called "Thu" on the first chart, I want to automatically search f ...

What is the reason behind the escape key not functioning in the Ace editor?

While using the Ace JavaScript editor with vim keybindings, I encountered an issue. Whenever I press the escape key to exit insert mode, the editor loses focus instead of exiting the mode. How can I capture this keypress in all modern browsers so that Ace ...

CSS: The search field's results are displayed in a width that is half of

There seems to be an issue with the search dropdown results on my website. When you click on the magnifying glass in the top menu and try to search, the results only appear as half the width of the search form. I would like to know how I can display it i ...

"Utilizing jQuery to apply a class based on the attributes of CSS

Is there a way in jQuery (or plain JS) to create a condition based on whether a div has a specific CSS attribute? For instance, I need jQuery to apply position:fixed to an element's CSS when another element has display:none, but switch back to positi ...

Looking to capture a specific data point from the $response object

<?php $apiKey = 'HnUvAYIy5hO7iPki'; $apiSecret = '9HBkibOphng7w4p1ZdiiVJgzRI4kpD4Q'; $msg = filter_input(INPUT_GET,"msg",FILTER_SANITIZE_STRING); $message = array( 'message' => array( 'message' =& ...

Showcasing both text and image side by side

https://i.sstatic.net/zR1G1.png Our current method for displaying text in one line and an image below it is shown below. I attempted to achieve this using position : relative: top: xxpx; bottom: xxpx;, but I believe there may be a more efficient way to c ...

jQuery: Expand the list when the page loads

Recently, I've been in search of a simple solution: How can I create a side navigation that expands with animation when my page loads? Surprisingly, the usual tutorial websites I frequent don't seem to have what I'm looking for. The closest ...