Fade-in effect on one DIV element impacting the values of other div

As a newcomer to jquery and JavaScript, I'm facing some challenges in getting the desired functionality. Currently, I am trying to animate three images simultaneously - one moving downward (iphone), another fading in (shadow), and the third one animating upwards while fading in (reflection). However, my code is making all elements fade in at the same speed, despite having different time values for each div. Additionally, when I attempt to animate the reflection, it pulls down all the elements if I modify the start value of the div. This issue seems to stem from the reflection being the first element in the "wrap" div. While I want the iphone overlapping the shadow and reflection, changing this order doesn't seem feasible. So, how can I trigger the reflection div first? I tried using z-values but that didn't work. Any suggestions?

<!DOCTYPE html>
<html lang="en>
<head> 

  <script src="jquery-1.3.2.min.js" type="text/javascript"></script>
  <link rel=StyleSheet href="external_style_sheet.css" type="text/css">

  <script type="text/javascript">

     $(function() {
        $('#iphone').animate({"top" : "1000px"}, 1200);
        $('#shadow').fadeIn(1800);
        $('#reflection').fadeIn(1800);

     });

  </script>
</head>

<body id="index" class="home">


<div id="wrap" > 
   <div id="left" />  
   <div id="right" >
      <div id="reflection" />
      <div id="shadow" />
      <div id="iphone" />
</div>



</body>
</html>

And the CSS

    `p {font-family: georgia, serif; font-size: x-small;}
hr {color: #000000; height: 1px }
a:hover {color: #ff0000; text-decoration: none}

body {
  background-color:#1b1a1f;

}



#reflection {
  margin-top:0px;
  margin-left: 400px;
  position:relative; 
  width: 414px;
  height: 993px;
  background-image: url("images/reflection2.png");
  display: none;
  z-index: -1;

}

#shadow {
  margin-top:0px;
  margin-left: 0px;
  position:absolute; 
  width: 414px;
  height: 818px;
  background-image: url("images/shadow3.png");
  display: none;
  z-index: 1; 
}


#iphone {
  margin-top:-1000px;
  margin-left: 0px;
  position:relative; 
  width: 414px;
  height: 818px;
  background-image: url("images/iphone_2.png");
  z-index: 0;
}



#wrap {
  width:800px;
  margin:0 auto;
  background-image: url("images/logo.png");
}


#left {
  float:left;
  width:500px;
}

#right {
  float:right;
  width:500px;

}

HTML
<div id="bar">Content</div>

Answer №1

It seems like you're almost there, but there are a few important things to keep in mind...

  • Double check that your HTML is properly structured with opening and closing div elements
  • Avoid using a z-index of -1; stick to positive values with a 5-level spacing for each element
  • Add "position: relative;" to #right, set the height and width manually, then use "position: absolute;" for #reflection, #shadow, and #iphone to prevent shifting during animations (ensure compatibility with your page layout)

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

Exploring textboxes with jQuery loops

Is there a way to clear all these textboxes by iterating through them using Jquery? <div class="col-md-4" id="RegexInsert"> <h4>New Regex Pattern</h4> <form role="form"> <div class="form-group"> &l ...

I am looking to adjust the height of my MUI Grid component

Recently exploring React, and I'm looking to set a height limit for MUI Grid. I've structured my project into 3 sections using MUI grid components. My goal is to restrict the page height in order to eliminate the browser scrollbar. If the conten ...

differentiating between user click and jquery's .click() method

There are <a href=".. tags on a page with an inline onclick attribute. If a user clicks one without being logged in, they will be prompted to log in. After logging in and the page refreshes, jQuery will trigger .click() on the <a> element to redir ...

Webpage Text Animation

This is the visual representation of my webpage: https://i.stack.imgur.com/tYq34.png I am seeking to implement a uniform animation effect for the text "Carlos Qiano" and "Lorem Ipsum", similar to the link below: https://i.stack.imgur.com/XVnBS.jpg Note: ...

A unique design using Masonry.js featuring a stylish two-column layout showcasing "elevated" blocks of varying sizes

Context I decided to use Masonry.js for this project because I felt it was the most straightforward way to achieve the desired effect, although it might not be the perfect tool for the task at hand. Objective The goal is to create a two-column layout wi ...

Converting HTML code into executable PHP code

I'm having trouble embedding PHP into an HTML file. I modified my .htaccess to recognize HTML files as PHP, but when I attempt to open the .html file in my browser, it gets downloaded instead of being processed and shown. UPDATE: Here is what's ...

`Some issues arise when using jQuery`

Can you confirm if this is HTML code? <div class='title centered'>SCE</div> <div class='description'> Magna tristique pulvinar porta montes, scelerisque odio montes porta habitasse, ut, arcu scelerisque v ...

Get a collection of strings from a WCF service triggered by jQuery

After calling my service to retrieve a list of strings, I encountered an error message. $(document).ready(function () //executes this code when page loading is done { $.ajax({ type: "POST", url: "Services/pilltrakr.svc/getAllUsers", ...

How to target CSS when a DIV does not have a particular sibling

I am currently dealing with HTML markup that is being generated by a third-party application. I am in the process of styling it to fit my branding, but I have encountered a challenge that I cannot figure out. Most of the time, the HTML structure consists o ...

What is the best way to generate a new CSRF token in LARAVEL using ajax?

My form contains numerous fields and allows users to add an unlimited number of additional fields. However, if a user takes too long to fill out the form, the CSRF token expires, resulting in a "CSRF token mismatch" error when they submit it using LARAV ...

What could be causing my dropdown links to malfunction on the desktop version?

I've been developing a responsive website and encountering an issue. In desktop view, the icon on the far right (known as "dropdown-btn") is supposed to activate a dropdown menu with contact links. However, for some unknown reason, the links are not f ...

The font rendering in Safari appears to have distinct differences compared to other web browsers

My concern is related to the HTML tag below: <a href="/partner-team/team" class="button button__style--1">MEHR</a> This is how the CSS appears: a { text-decoration: none; } .button { padding: 0.2rem 4rem; curso ...

Tips for transferring data from the Item of a repeater to a JavaScript file through a Button click event for use in Ajax operations

I am working with a repeater that displays data from my repository: <div class="container" id="TourDetail"> <asp:Repeater ID="RptTourDetail" runat="server" DataSourceID="ODSTTitle" ItemType="Tour" EnableViewState="false" OnItemDataBound="Rp ...

javascript retrieving JSON data through an API request from a redirected URL

I am retrieving JSON data from the Glitch API. Upon opening the link, it redirects to a different domain (the domain was changed from gomix.me to glitch.me) When using Postman for both HTTP requests, I receive identical JSON data. However, there is a d ...

Meteor chat platform now offers the option to create multiple chat rooms

I've been working on an application that features multiple chat rooms. Currently, one of the rooms is functional in terms of sending and receiving messages. However, when I navigate to a different room and try to send a message, the message doesn&apos ...

What are some strategies for keeping the focus state on the parent item in a dropdown menu?

When I interact with the dropdown menu in my navigation bar, the color changes for the child items. How can I make sure that the parent item maintains the same colored background even after clicking elsewhere on the page? To better understand the issue, i ...

Manipulating files with the Play framework

I am looking to upload a file from the client side and process it on the server side without having to reload the entire webpage. I am currently working with Scala in Play framework 2.X, utilizing separate HTML and JavaScript scripts. The file types I am w ...

the combination of class and type functions as a jquery selector

<button class="actionButton default" type="submit"> Save</button> Can you select this button by both its class and type using a jQuery selector? I attempted the following, but it did not work: var saveBttn = $('.actionButton.default [ty ...

The jQuery html function may encounter issues when used in Chrome browser

Can someone help me figure out why this code isn't functioning properly in Chrome, even though it works fine in Safari? I've been searching for a solution but haven't had any luck! jQuery.noConflict(); jQuery(document).ready(function() { ...

When collapsing an accordion, Bootstrap radio buttons fail to properly select

I have attempted various methods to achieve the desired functionality of having the accordion content close and open accordingly when checking a radio button, while also having the button visually appear as 'checked'. For a more in-depth example, ...