Animation of a balloon floating in the air

After creating a basic animation of a balloon moving from bottom to top, I encountered an issue. The first loop works smoothly, but then the movement becomes random. Ideally, I want balloons to ascend consecutively without any erratic behavior, and continue in this pattern.

<div id="parent">
    <div class="message">1. Bob</div>
    <div class="message">2. Alice</div>
    <div class="message">3. Eve</div>
</div>


jQuery.fn.verticalMarquee = function(vertSpeed, horiSpeed, index) {

    this.css('float', 'left');

    vertSpeed = vertSpeed || 1;
    horiSpeed = 1/horiSpeed || 1;

    var windowH = this.parent().height(),
        thisH = this.height(),
        parentW = (this.parent().width() - this.width()) / 2,
        rand = Math.random() * (index * 1000),
        current = this;

    this.css('margin-top', windowH + thisH);
    this.parent().css('overflow', 'hidden');

    setInterval(function() {
        current.css({
            marginTop: function(n, v) {
                return parseFloat(v) - vertSpeed;
            },
            marginLeft: function(n, v) {
                //return (Math.sin(new Date().getTime() / (horiSpeed * 5000) + 1000) + 1) * parentW;
                return (Math.pow(new Date().getTime() / ( 5000) + 1000) + 1);
            }
        });
    }, 15);

    setInterval(function() {
        if (parseFloat(current.css('margin-top')) < -thisH) {
            current.css('margin-top', windowH + thisH);
        }
    }, 250);
};
var message = 1;
$('.message').each(function(message) {  
    $(this).verticalMarquee(0.5, 0.5, message);
    message++
});

parent {

    left: 0;
    top: 0;
    width: 400px;
    height: 100%;
}

.message,.message-1 {
    height: 120px;
    width: 120px;
    background-color: orange;
    color: white;
    z-index: -9999;
    line-height: 115px;
    text-align: center;
    font-family: Arial, sans-serif;
    font-weight: bold;

    -webkit-border-radius: 60px;
    -moz-border-radius: 60px;
    border-radius: 60px;
}

Fiddle: https://jsfiddle.net/znrhkf3c/12/

Your assistance on this matter would be greatly appreciated.

Answer №1

One way to achieve this animation is by utilizing only CSS. You have the flexibility to adjust the duration and delay based on your requirements.

#parent {
position: relative;
width: 400px;
height: 100vh;
overflow: hidden;
}
.message {
position:absolute;
left: 0;
bottom: -120px;
height: 120px;
width: 120px;
background-color: orange;
color: white;
line-height: 115px;
text-align: center;
font-family: Arial, sans-serif;
font-weight: bold;
border-radius: 60px;
animation: move 6s infinite linear;
}
.message:nth-child(2){
left:120px;
animation-delay: 2s;
}
.message:nth-child(3){
left:240px;
animation-delay: 4s;
}
@keyframes move {
0% {
bottom: -120px;
}
100% {
bottom: 100%;
}
}
<div id="parent">
   <div class="message">Bob</div>
   <div class="message">Alice</div>
   <div class="message">Eve</div>
</div>

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

Sending an AJAX request with conditionals using PHP

I am working on a form where selecting a Name populates two other dropboxes automatically. With the help of an AJAX script, a variable is passed to another page to retrieve data from a query and display it. The current setup successfully updates one dropbo ...

Ways to implement a backup plan when making multiple requests using Axios?

Within my application, a comment has the ability to serve as a parent and have various child comments associated with it. When I initiate the deletion of a parent comment, I verify the existence of any child comments. If children are present, I proceed to ...

Enhance User Experience with JQuery Autocomplete for Internet Explorer 8 Using ASMX Web Services

Help Needed! I have been trying to implement a Web Service (ASMX) file on my website. When I access and query the page, I receive the desired results. The problem arises when I attempt to add autocomplete functionality to a textbox in my ASP.NET applicati ...

Looking for a solution to create a stationary header on iOS devices running version

I am facing an issue where the header on my page is not fixed at the top when the keyboard appears. Instead, whenever I click on a text box, the keypad comes up and the entire page, including the header, moves to the top. This requires the user to scroll t ...

Is there a workaround for Angular ui-sref param removing spaces?

Looking for help with an anchor tag: <a ui-sref="view({id:{{ id }}})" data-toggle="tooltip" data-placement="top" title="View Details"><i class="fa fa-search-plus fa-2x icon-color"></i></a> The issue I'm facing is with the id ...

Clicking on anchor links does not cause the link to bubble up to the document, but right-clicking allows the

Below is the code snippet that I am currently working with - <ul id="sliderNav"> <li class="navTitle"><h3>Navy Mobile App</h3> <p class="navContent"><br>New Navy mobile application for accessing Navy information on ...

Get an Array Using AJAX in PHP and JavaScript

Section 1 I want to retrieve an Array from PHP and use it in JavaScript. I have created a file using the fwrite function in PHP, then included that file in my next .load method inside a Div. The new PHP file contains an "include 'somefile.php';" ...

Saving user editable content from a div into an array with a button click

I'm currently developing a webpage using HTML and PHP, where I aim to present users with questions and collect their answers. At this stage, I have organized the questions in an array as shown below: <?php $questions = array( '0' =& ...

Discovering the Xpath for the Search function on an Angular-based website

Seeking to automate a search on an angular website using Python, I have encountered difficulty in locating the correct Xpath for certain HTML elements. The specific line of code I need the Xpath for can be found on this website highlighted in blue. https: ...

Get your hands on the base64 image by triggering the save as popup and downloading

I am facing a challenge with downloading a base64 image onto the user's machine. So far, I have attempted the following steps: var url = base64Image.replace(/^data:image\/[^;]+/, 'data:application/octet-stream'); window.open(url); an ...

The module '@algolia/cache-common' is missing and cannot be located

summary: code works locally but not in lambda. My AWS lambda function runs perfectly when tested locally, utilizing Algolia within a service in the server. Despite installing @algolia/cache-common, any call to the lambda results in a crash due to the erro ...

Unable to replace default typography in MUI with custom typography theme on Next.js

In my Next.js React project, I am utilizing Material-UI (MUI) with a customized theme. Although the colors from the theme are being applied successfully, I am encountering difficulty in adjusting the default font sizes of H2 and H5 elements. Even though I ...

Using an Ajax call within an event handler function

After spending a full day attempting to execute an AJAX call within an event handler function, I've tried various combinations of when(), then(), and done(), as well as setting async: false. However, I keep encountering undefined errors despite my eff ...

Recursive function in JavaScript for parsing intricate JSON object or array

I received a JSON response that looks like this: { "data":[ { "type":"node--base_product_coffee", "id":"6dbb5a52-13ea-4f74-8af9-eb9e3ba45918", "date":"1990 ...

Click on the image to send the form

Is it possible to submit a form by clicking on an image without using jQuery? The code snippet provided below is not working for me. Can you suggest an alternative method? Razor @using (Html.BeginForm("AssignLabels", "Home", FormMethod.Post, new { name = ...

problem with a scrolling div appearing when the direction details for Google Maps are shown

I've set up a Google Map that shows the starting address with a marker, and there's also a text input for entering the destination address. Clicking on the GetDirections button will display the directions in a div. Here's the code snippet: a ...

Using the next/dynamic library to import components in Next.js can be complex and confusing at first

Embarking on my first foray into building a NextJs app for production, I find myself in uncharted territory as a newcomer. My current project involves incorporating PeerJs for real-time communication, yet encountering an issue when attempting to import it ...

Inserting multiple rows of data into a MySQL database in a single page using only one query in PHP

This snippet shows a MySQL query being used to update and insert data into a database: if ($_POST["ok"] == "OK") { $updateSQL = sprintf("UPDATE attend SET at_status=%s, at_remarks=%s WHERE at_tt_idx=%s", GetSQLValueString ...

Aligning Content in the Center of a CSS Grid

Having difficulty with a CSS Grid layout that should consist of 7 squares per row to create a calendar style design. The layout seems fine, but I am struggling to center the title and subtitle in the middle of each item. I have tried using margin:auto, ver ...

Having trouble retrieving data from getStaticProps

I'm currently developing a project using next.js and I am attempting to fetch a list of gyms in the getStaticProps function. Here is my code snippet: import { MapContainer, TileLayer, Marker, Popup } from "react-leaflet"; import { useState } ...