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

Is transforming lengthy code into a function the way to go?

I have successfully implemented this code on my page without any errors, but I am wondering if there is a more concise way to achieve the same result. Currently, there is a lot of repeated code with only minor changes in class names. Is it possible to sh ...

Position a dynamic <div> in the center of the screen

My goal is to design a gallery page with a list of thumbnails, where clicking on a thumbnail will open the related image in a popup div showing its full size. The issue I'm facing is how to center the popup div on the screen, especially when each pic ...

Ways to match a string against a numeric value

I have a span id with textContent which have their own time(hour/minutes) <div class="here"> <span class="time" >8 min</span> </div> <div class="here"> <span class="time" >22 min&l ...

Export data from tables into an Excel spreadsheet using ReactJS

I need to export multiple tables from my webpage into a single Excel sheet. <div>{store.ratecardList.map(ratecard => { return( <div key={ratecard.ratecardId} className="box-filter"> <table id={ratecard.ratecardId} widt ...

fetching the name of the button from a servlet on a JSP page

I am currently working on a project in eclipse using JSP. I am facing an issue with detecting which button is pressed when submitting a form with an ajax call. The request.getParameter(button-name) method is returning null within the doPost method of the s ...

Creating virtual hover effects on Android browsers for touch events

My Wordpress website is currently utilizing Superfish 1.5.4 to display menu items. The menu on my site includes several main menu items, which are clickable pages, and hovering over these main items should reveal sub-menu options. When I hover over a mai ...

What is the method for inserting form control values into a QueryString within HTML code?

Struggling with passing HTML form control values into a QueryString for page redirection. While I can easily input static values into a QueryString and retrieve them using PHP's GET method, I am encountering difficulties when it comes to dynamic valu ...

Using Jquery to bind events for selecting focus in and out

There seems to be an issue with binding jQuery events to a select element. The desired behavior is for the .focus class to be added when the select is clicked. However, the logic breaks when an option is selected from the dropdown. See it in action here: ...

Adjusting the size of HTML checkboxes for creating PDF documents

Currently facing a dilemma. When it comes to resizing checkboxes in HTML, the common recommendation is to use JavaScript to prompt the browser to adjust the size of the elements. However, in our scenario, we rely on wkhtmltopdf, a command line tool that u ...

Click on a text link to scroll to and either open or toggle a Bootstrap accordion

I am currently working on a bootstrap accordion with the following structure: <div class="support-accordion"> <div class="accordion" id="accordionExample"> <div class="accordion-item ...

Improving search functionality with autocomplete in EasyAdmin 3.3 filter options

Is there a quick solution in easyadmin 3.3 to implement an autocomplete feature for filters? I have successfully used it in forms, but encountering an undefined error with filters. public function configureFields(string $pageName): iterable { r ...

I encountered a SyntaxError indicating a missing ")" right before utilizing jQuery in my code

When trying to run the code below, I encountered an error in the console stating SyntaxError: missing ) after argument list. $(document).ready(function() { $(".blog-sidebar-form form").before("<p class="blog-sidebar-inform>Dummy Text</ ...

Ensuring Consistent Item Widths in a Loop using JavaScript or jQuery

In my code, I created a function that dynamically adjusts the width of elements in a loop to match the widest element among them. // Function: Match width var _so20170704_match_width = function( item ) { var max_item_width = 0; item.each(function ...

Extracting JSON data in PHP and presenting it in a tabular format

Below is a snippet of my HTML code, <html> <head> <script src="js/jquery.js"></script> </head> <body> <input type="text" name="query" id="queryBox"> <button id="load_basic" value = "button">search</but ...

Embedded HTML code within a table cell

How can I dynamically build an HTML string and display it inside a cell in reactJS' ag grid? Here's my example: function generateHtmlString(props) { let myHtmlString = "<span>a</span>"; myHtmlString += "--"; myHtmlString += "&l ...

Using inline JavaScript to style an element when clicked

Looking for assistance with styling a link. I've connected an external stylesheet to my HTML file, so that part is all set. The goal is to modify the text-decoration when the onclick event occurs. Here's what I currently have: <a class="dopel ...

Attempting to position items within a container

Currently, I am in the process of creating a list of job opportunities to be displayed on a side bar of our careers page. Each job listing should include the job title along with an apply button enclosed within a rounded grey box that allows for some spaci ...

Guide on showcasing all entries in the database within the body section of an HTML table

Looking to showcase data from a table inside the body section of an html page This is the code I've been working on: <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="vi ...

Fire the onChange Event after the Select (Combobox) has been modified via a PHP Script

Below is the HTML code snippet for a combobox: <select name="cmbdegree" id="cmbdegree" class="styledselectevents"> <option value="0">Select Degree</option> <?php $newque="SELECT * FROM degrees"; ...

A continuous jQuery method for updating select option values

I'm currently working on a form and using jQuery to make some alterations. The form consists of multiple select elements, and I want to change the value of the first option in each of them. However, as the form allows for dynamic addition of new selec ...