Tips for smoothly animating text alongside a circular shape using CSS transformations

I am currently working on a mobile site and the animation I'm aiming for is quite specific. First, a large circle will appear, covering the entire screen like a splash screen. Then, this big circle will smoothly transition into a smaller circle in the bottom left corner. At the same time, an image inside the circle will also move towards the bottom left.

The issue I'm facing is that while the circle transitions correctly, the text doesn't move smoothly to the bottom left; it kind of shifts left first before moving down. Below is the code snippet I've been experimenting with:

setTimeout(function() {
  let i = document.getElementById("test");
  let d = document.getElementById("icon-img");

  i.classList.add("active");
  d.classList.add("active");
}, 2000);
.test {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  transition: all 3s ease;
  background: gray;
  transform: scale(100);
  border-radius: 30px;
  left: 20px;
  bottom: 20px;
}

.test.active {
  transform: scale(1);
  transition: all 2s ease;
  left: 20px;
  bottom: 20px;
}

.wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.myclass {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.before {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 2s ease-in-out;
  width: 50%;
  height: 50%;
  position: fixed;
  font-size: 50px;
}

.before.active {
  left: 20px;
  bottom: 20px;
  width: 40px;
  height: 40px;
  font-size: 15px;
  position: fixed;
  transform: translate(0, 0);
}
<div class="wrapper">
  <div id="test" class="test"></div>
  <div class="myclass">
    <img src="./logo.svg" id="icon-img" class="before"></img>
  </div>
</div>

Answer №1

One issue arises when certain properties lack an initial value, resulting in a sudden transition effect.

To address this, the following code snippet eliminates the flex property for image centering, opting instead to use left and bottom combined with translation for the initial alignment.

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title></title>
  <style type="text/css">
    .test {
      position: fixed;
      left: 0;
      bottom: 0;
      width: 40px;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 40px;
      transition: all 3s ease;
      background: gray;
      transform: scale(100);
      border-radius: 30px;
      left: 20px;
      bottom: 20px;
    }
    
    .test.active {
      transform: scale(1);
      transition: all 2s ease;
      left: 20px;
      bottom: 20px;
    }
    
    .wrapper {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100vh;
    }
    
    .myclass {
      width: 100%;
      height: 100%;
    }
    
    .before {
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 2s ease-in-out;
      width: 50%;
      height: 50%;
      position: fixed;
      font-size: 50px;
      left: 50%;
      bottom: 50%;
      transform: translate(-50%, 50%);
      background: pink;
    }
    
    .before.active {
      left: 20px;
      bottom: 20px;
      width: 40px;
      height: 40px;
      font-size: 15px;
      position: fixed;
      transform: translate(0, 0);
    }
  </style>
</head>

<body>
  <div class="wrapper">
    <div id="test" class="test"></div>
    <div class="myclass">
      <img src="./logo.svg" id="icon-img" class="before"></img>
    </div>
  </div>
  <script>
    setTimeout(function() {
      let i = document.getElementById("test");
      let d = document.getElementById("icon-img");

      i.classList.add("active");
      d.classList.add("active");
    }, 2000);
  </script>
</body>

</html>

Please note that the image is assigned a pink background since no actual image is provided, allowing visualization of its position and size.

The question highlights two different transition durations - 2s and 3s. This may imply a staggered arrival for the image and text. While retained in the snippet, perhaps simultaneous timing was originally intended?

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

Newbie struggling with executing JavaScript in Visual Studio Code

Hey there! I'm new to coding and have been struggling for the past couple of hours trying to get a simple JavaScript code to run on VSC. Can anyone lend a hand in helping me set up my sandbox correctly? Here's a snapshot for reference: https://i ...

Difficulties with vertical scrolling on mobile devices due to the use of "-webkit-overflow-scrolling: touch"

In the midst of creating a new mobile website design that is responsive, an issue arose during testing on my phone. It seemed impossible to scroll vertically past a certain point if there was horizontal scrolling involved. To better illustrate this proble ...

Remove any JSON objects in JavaScript or AngularJS that match another JSON object

JSON A ['711','722','733','744'] JSON B [{pid: 711, name: 'hello'},{pid: 733, name: 'world'}, {pid: 713, name: 'hello'},{pid: 744, name: 'hellosdaf'}] I am attempting to remo ...

Utilize varying sizes within a single column using Bootstrap

I am struggling to create a heading that spans the entire width of my listview within Bootstrap. Despite being in the same column, the heading does not extend as far as the listview. I desire for the title to stretch all the way across the list, leading m ...

Showcase three elements next to each other on the same row (Photo Gallery, Description, and Contact Form)

I am attempting to showcase three divs in a single line while working on a Subtheme for the Drupal 8 Bootstrap Theme. These particular divs are fields nested within a view known as viewproducts. The divs include: Juicebox Photo Gallery; ...

Is there a way to access an SD card by clicking on an HTML link using JavaScript?

UPDATE: I am seeking a way to embed an HTML file with JavaScript or jQuery that can directly access the contents of the SD card while being opened in a browser. Currently, I have posted code for accessing it through an activity, but I want to be able to d ...

PHP Code for Removing Selected Entries

Is it possible to delete specific records from a table? For example, if I have records in my table like this: Monday | Tuesday | Wednesday IT | IT | IT When I delete "IT" from any day, all instances of "IT" are deleted from all days. However, I ...

In my Node.js application, I am attempting to prevent other sockets from accessing a specific button. Once a player has clicked the button, I want to ensure that it is no longer clickable for other players

When a player selects a seat, it is necessary to remove the buttons from the DOM in order to prevent multiple players from occupying the same seat. All buttons should be hidden on the client side once a player sits down to prevent them from changing seats. ...

Click event handling in child components with Vue 2

I have a basic component with the following structure: <template> <span @click="clickHandler" :class="className"></span> </template> <script> export default { name: "PlusIconComponent", props: { ...

Transfer the value of a JavaScript variable to a PHP variable

var javascript_data = $("#ctl00").text(); <?php $php_variable = ?> document.write(javascript_data); <? ; ?> Is there a way to transfer the javascript_data into the php_variable? I'm encountering an issue with this code. Any suggestions? ...

Newly added rows to the table after filtering remain visible

I am currently using the DataTable API and jQuery to create a table by fetching rows from the server. However, I encounter an issue when I click a button to load additional rows and append them to the end of the table. The problem arises when I try to hide ...

Prevent ng-click from functioning in AngularJS when a specific variable is met

<span class="column__list--total fa" ng-class="{'fa-check': skill.done == 1, 'fa-times red': skill.done == 0}" ng-click="skill.disabled || toggleSkill(skill.id, person.id)" ng-hide="$root.user[0].auth == 2"></span> <span ...

placing a see-through overlay onto a text-filled div

I have a text within a div and I am looking to overlay a transparent image on this div. When the image is clicked, the content of the background div should be displayed with the div changing its width to show the entire text with a scroll bar. Does anyone ...

How to display a name in an iframe using React

When I retrieve the movie name in React, it appears correctly as {movie.name} / {movie.enname} ({years}) . However, when I try to display this name within an iframe window at https://example.com/movie/{movie.name}, it does not show up properly. Here is th ...

Having trouble aligning photos in the grid

I am facing an issue aligning my menu and image grid. The grid is inline-block but the first item stays stuck in the upper right-hand corner no matter what I do, without affecting the navigation menu placement. Additionally, when testing locally, everythin ...

Tips for creating a Bootstrap table with a "table-bordered" style, fixed header, and scrollable body

How can I keep the table header fixed while allowing the body to scroll without breaking the table layout? I've tried using the CSS below, but it results in the width of the header columns being different from the width of the body columns. Any sugges ...

What could be causing the CSS fade-in effect to not be functioning properly?

HTML: <ul class="nav"> <ul> <li><a href="index.php">Home</a></li> <li><a href="#">A</a> <ul> <li><a href="x.php">X</a></li> <li><a href="y.php ...

What could be the reason behind the drop down menu not displaying functional links?

Currently, I am learning bootstrap by experimenting with examples. I am trying to create a drop down menu that includes three links: the main tab should link to someroute, while the other two links revealed by the drop down should lead users to route3 and ...

The text does not display on the screen as expected

I attempted to create a calculator using vue.js. Unfortunately, I encountered an issue where the second string value does not get appended on the calculator screen upon clicking the next button. This problem arose after implementing some logic for arithmet ...

Encountering an ongoing problem with trial repetition in JsPsych, which is causing the looping to continue endlessly without

As a beginner in JsPsych, I'm diving into creating a basic math quiz task to sharpen my skills. The goal is to generate random math questions as prompts and stop the task after 10 correct answers. I've managed to code that selects random math pro ...