The animation in the HTML, CSS, and JavaScript code is not functioning properly

Recently, I came across an interesting YouTube video. Here is the link:

https://www.youtube.com/watch?v=2ak37WrbSDg

The video featured a captivating animation at the beginning, utilizing span text. Intrigued, I attempted to modify it by incorporating images instead. However, my efforts were unsuccessful when I tried to use images in place of text. Below is the HTML code snippet that I was working on:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
    <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300&display=swap" rel="stylesheet">
</head>
<body>
    <div class="intro">
        <div class="image-slider">
            <div class="left leftright" >
                <div class="leftmain" style="background-image: url(images/left.jpg);"></div>
            </div>
            <div class="right leftright">
                <div class="main" style="background-image: url(images/right-bike.jpg);"></div>
            </div>
        </div>

        
    </div>

    <header>
        <h4>hello world</h4>
    </header>
    

    <script src="script.js"></script>
</body>
</html>

This is the CSS code associated with the HTML structure outlined above:

*
{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

header 
{
    position: relative;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}

header h4 
{
    position: absolute;
    left: 10%;
    bottom: 1rem;

}

.intro
{
    position: fixed;
    z-index: 1;
    left: 0;
    right: 0;
    width: 100%;
    height: 100vh;
    transition: 1s;

}

[right - sections for styling and animations omitted for brevity]

Furthermore, there is a JavaScript script included to handle interactions and animations within the webpage:

// JavaScript function to control animations on page load

let intro = document.querySelector('.intro');
let image = document.querySelectorAll('.leftright')

window.addEventListener('DOMContentLoaded', ()=>
{
    [JavaScript functionality and timing functions continued...]
})

In conclusion, despite designing the webpage to have a dynamic introduction where split images slide in from both sides and rise together, the live server displays a blank screen. Seeking assistance to troubleshoot this issue. Any help would be greatly appreciated.

Answer №1

It appears that the browser is handling all UI changes simultaneously. The transition effect involves the left and right div elements with background images moving in, followed by the .intro element shifting to a -100vh position. These changes are executed together by the browser, resulting in a complete refresh/repaint of the client area within the browser window.

To achieve the desired outcome, here's a combination of JavaScript/CSS/HTML code: the images converge from both sides before the entire intro element ascends out of view.

const intro = document.querySelector('.intro');
const leftRightContainers = document.querySelectorAll('.leftright');
const leftContainer = document.querySelector('.leftright.left');

window.addEventListener('DOMContentLoaded', () => {
  // 'transitionend' event handler function
  const transitionendHandler = () => {
    intro.classList.add("move-up");
    leftContainer.removeEventListener("transitionend", transitionendHandler);
  };
  // Add 'transitionend' event handler
  leftContainer.addEventListener("transitionend", transitionendHandler);
  // Trigger transition
  setTimeout(() => {
    leftRightContainers.forEach((elem, index) => {
      elem.classList.add('active', 'fade');
    });
  }, 100);
});
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Poppins', sans-serif;
}

header {
  position: relative;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

header h4 {
  position: absolute;
  left: 10%;
  bottom: 1rem;
}

.intro {
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 100vh;
  transition: top ease-in-out 1s;
  transition-delay: 0.5s;
}

.intro.move-up {
  top: -100%;
}

.leftright {
  height: 100%;
  width: 50%;
  position: absolute;
  top: 0;
  opacity: 0;
}

.leftright.left {
  left: -100%;
}

.leftright.right {
  left: 100%;
}

.leftright.active {
  right: 0;
  opacity: 1;
  transition: ease-in-out 0.5s;
}

.leftright.left.active {
  left: 0;
}

.leftright.right.active {
  transform: translateX(-100%);
}

.leftright .img-container {
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center center;
  height: 100%;
  width: 100%;
}

.image-slider.fade {
  bottom: 150px;
  opacity: 0;
  transition: ease-in-out 0.5s;
}
<div class="intro">
  <div class="image-slider">
    <div class="leftright left">
      <div class="img-container" style="background-image: url(https://mdn.github.io/learning-area/javascript/building-blocks/gallery/images/pic3.jpg);"></div>
    </div>
    <div class="leftright right">
      <div class="img-container" style="background-image: url(https://mdn.github.io/learning-area/javascript/building-blocks/gallery/images/pic2.jpg);"></div>
    </div>
  </div>
</div>


<h4>hello world</h4>

Note: Initially, there might be a slight delay when running the code snippet due to the browser downloading images into the background of the .image-container elements. Subsequent runs will perform as expected since the images are cached. To address this issue, consider initiating the left-right-move-up intro animation after the images have fully loaded into the image container elements by setting up an 'onLoad' event listener for each image container before starting the intro animation.

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

Arranging HTML Lists in Perfect Order

I am working with an HTML list that contains links styled as background images rather than text. The container is 200px tall and I would like the links to be centered inline within the container. Usually, I would use line-height:200px; for text to achieve ...

What is the best way to extend an image to fill the width of a webpage?

Can you advise me on how to expand the image to fit the width of my webpage? If possible, could you take a look at this website: Poklanjam The specific image I am referring to is the one of the city on the left-hand side. What additional CSS code should ...

Leveraging 2-dimensional indexes in collaboration with the $geoNear operator

I encountered an issue while attempting to use geoNear with aggregate as I received the following error message: errmsg: "'near' field must be point" The reason for this error is because my location field is represented as [Number]: var locati ...

How can I create a design that adjusts to show 5 columns on larger screens and 2 columns on smaller screens using Bootstrap 4?

I am working on a responsive column layout for an online store. I need to display 5 columns on large screens and 2 columns on mobile screens using Bootstrap4. However, on screens below 576px width, only one column is being rendered instead of two. How ca ...

What could be the reason for bootstrap failing to recognize and apply my variables?

Whenever I set the text color to green using this code: @textColor: green; It works perfectly and changes the text color, but when I try to modify grid column width and gutter width with this code: @gridColumnWidth: 10px; @gridGutterWidth: 0px; @flu ...

One way to include query parameters before initiating navigation in Angular

Imagine having two components called A and B. When Component A navigates to /a?random=random and B navigates to /b, I need to include the authUser query parameter before the navigation begins. This way, the final URLs should look like this: /a?random=rando ...

Popup modal is obstructed by carousel indicator

I'm having trouble with the following issue: The 3 dots represent my carousel indicator. My problem is that the carousel indicator is blocking my pop-up modal image. I've tried adjusting the z-index of the modal without success. Here is the code ...

Using jQuery to insert a new string into the .css file

I'm currently working on a jQuery function to make my font size responsive to changes in width. While I am aware of other options like Media Query, I prefer a solution that offers smoother transitions. Using vw or vh units is not the approach I want t ...

Error message "getSystemErrorName is not a function" is received while using the Google Data Studio community connector local development tool

Currently, I am utilizing the guidelines provided in the Google Data Connector's local development resource to establish a fresh community-connector. However, upon executing the command npx @google/dscc-gen connector, I encounter an error stating getS ...

Exchange one HTML element with a different HTML element

I've been attempting to change an HTML tag using PHP or jQuery. The current default tag is: <li class="dropdown"> <a href="index.html" class="dropdown-toggle"> Home</a></li> My desired replacement for the above HTML tag is: ...

Utilizing jQuery to add elements to a webpage

I need to populate an empty div on my webpage using jQuery. Here's an example: <div class="content"> </div> After the first insertion, I want the markup to look like this: <div class="content"> <div class="inserted first"& ...

Using Javascript to target elements with identical attributes

I have some HTML similar to the code below: <form name="test_form"> <input type="hidden" name="product_id" value="560"> <input type="hidden" name="product_name" value="test product"> <input type="hidden" name="product_type" value="7"& ...

Vue warning: You are trying to access a property or method that is not defined on the instance but is being referenced during

The code snippet above was created to manage an event triggered by a button click var MainTable = Vue.extend({ template: "<ul>" + "<li v-for='(set,index) in settings'>" + "{{index}}) " + &qu ...

How can I incorporate Vue draggable feature in my project using cards?

I've been attempting to integrate vuedraggable with Vuetify Cards, but I'm facing an issue where the drag and drop functionality doesn't seem to work when the cards are in a single row. Interestingly, it works perfectly fine when they are di ...

The JavascriptExecutor in Selenium WebDriver using C# consistently returns null objects

I'm having trouble accessing HTML elements using jQuery with JavaScriptExecutor and consistently encountering null reference exceptions. Any idea what could be causing this issue? Below is the code snippet I'm working with: List<Object> ...

Designing borders for tables

My current table styling approach is as follows: #content table { width: 100%; margin-top: 1em; border-collapse: collapse; border: 1px solid #222; } #content table td { border: 1px solid #888; padding: .3em; } I aim to create tab ...

Tips for Building Common Controller Logic in CakePHP

I am in the process of developing a website where I have set up dynamic content for the footer, which is retrieved from a database. I am looking to create a single controller logic code that can be used across all pages on the site. Any suggestions or gu ...

The issue of HTML buttons malfunctioning within a label renderer in three.js

I am facing an issue where the HTML button is not working in the label renderer when both WebGLRenderer and LabelRenderer are used simultaneously. This causes various problems such as orbit control not functioning properly, buttons being unclickable, and a ...

When utilizing the AWS JavaScript SDK, the request header is missing the HTTP_X_CSRF_TOKEN

In my Rails application, I have implemented a feature that allows users to post answers to questions via ajax. Everything was working fine until I decided to incorporate the aws-js-sdk script in order to enable image uploads within the answer input field. ...

elasticsearch query for deletion only returns documents that are not found

I have been attempting to use the https://www.npmjs.com/package/elasticsearch-deletebyquery package to delete documents using a query. However, I keep receiving a "Not found" error. Here is my code snippet: client.deleteByQuery({ index: index, type: t ...