Insert item at the end of the box and move all elements upwards

Hello! I'm experimenting with creating something using javascript's createElement method. My goal is to achieve an effect similar to this image: https://i.stack.imgur.com/itKUK.gif

Currently, my code is functional, but the animation goes from top to bottom instead of bottom to top. Here's a snippet of my code:

function recal(color, user, content) {
            var element = document.createElement("p");
            element.className = "flyin";
            var spanelement = document.createElement("span");
            spanelement.appendChild(document.createTextNode(user + ': '));
            element.appendChild(spanelement);

            element.innerHTML = '<span style = "color:' + color+ ';font-weight:bold">' + user + ': </span>' + content;

            var x = document.getElementById('messagecontainer');
            x.appendChild(element);
            setTimeout(function () {
                element.classList.add('fade-out');
                element.onanimationend = (e) => {
                    if (e.srcElement.classList.contains('fade-out')) {
                        element.parentNode.removeChild(element);
                    }

                }
            }, 10000)
            ;
        }
.fadeout {
                opacity: 1;
                -webkit-transition: opacity 1000ms linear;
                transition: opacity 1000ms linear;
            }
            body {
                font-family: Arial;
                font-weight: bold;
                margin: 0px;
            }

            #messagecontainer{
                /* probably something here */
            }

            .flyin {
                -webkit-animation: test1 .2s linear;
            }

            @-webkit-keyframes test1 {
                0% {
                    -webkit-transform: translateX(75%);
                }

                100% {
                    -webkit-transform: translateX(0%);
                }
            }
            
            .fade-out {
                animation: fade 2s;
                -webkit-animation: fade .5s;
                -moz-animation: fade .5s;
            }

            @keyframes fade {
                from {
                    opacity: 1;
                }
                to {
                    opacity: 0;
                }
            }

            @-moz-keyframes fade {
                from {
                    opacity: 1;
                }

                to {
                    opacity: 0;
                }
            }

            @-webkit-keyframes fade {
                from {
                    opacity: 1;
                }

                to {
                    opacity: 0;
                }
            }
<button onclick='recal("blue","Komali","hello!")'>click me!</button><div id="messagecontainer"></div>

Is there a way to make it animate from the bottom rather than the top? Any assistance would be greatly appreciated.

Answer №1

Your progress is good, but you just have to include position: absolute; in the #messagecontainer and align it to the left bottom corner, like this:

#messagecontainer {
  position: absolute;
  left: 0;
  bottom: 0;
}

function displayMessage(color, user, content) {
  var element = document.createElement("p")
  element.className = "flyin"
  var spanelement = document.createElement("span")
  spanelement.appendChild(document.createTextNode(user + ': '))
  element.appendChild(spanelement)

  element.innerHTML = '<span style = "color:' + color + ';font-weight:bold">' + user + ': </span>' + content

  var x = document.getElementById('messagecontainer')
  x.appendChild(element)
  setTimeout(function() {
    element.classList.add('fade-out');
    element.onanimationend = (e) => {
      if (e.srcElement.classList.contains('fade-out')) {
        element.parentNode.removeChild(element);
      }

    }
  }, 10000);


}
.fadeout {
  opacity: 1;
  -webkit-transition: opacity 1000ms linear;
  transition: opacity 1000ms linear;
}

body {
  font-family: Arial;
  font-weight: bold;
  margin: 0;
}

#messagecontainer {
  position: absolute;
  left: 0;
  bottom: 0;
}

.flyin {
  -webkit-animation: test1 .2s linear;
}

@-webkit-keyframes test1 {
  0% {
    -webkit-transform: translateX(75%);
  }
  100% {
    -webkit-transform: translateX(0%);
  }
}

.fade-out {
  animation: fade 2s;
  -webkit-animation: fade .5s;
  -moz-animation: fade .5s;
}

@keyframes fade {
  from {
    opacity: 1
  }
  to {
    opacity: 0
  }
}

@-moz-keyframes fade {
  from {
    opacity: 1
  }
  to {
    opacity: 0
  }
}

@-webkit-keyframes fade {
  from {
    opacity: 1
  }
  to {
    opacity: 0
  }
}
<button onclick='displayMessage("blue","Komali","hello!")'>click me!</button>
<div id="messagecontainer"></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

Issue with jQuery AJAX error callback not triggering upon encountering an error

I'm currently facing an issue with implementing the management of an HTTP 413: Request entity too large error from my server. I've made the following attempt to address it: $.ajax({ url: "submit.php", data: { "data": POSTData ...

Sending an HTTP request from within an Express/Node.js application

I am currently in the process of setting up an express service for a program I am developing. The goal is to interact with an external API, retrieve the data, and store it in a MongoDB database that I have already set up. While this task may seem straight ...

Setting up SSL/TLS certificates with Axios and Nest JS

I have a Nest JS application set up to send data from a local service to an online service. However, the requests are not working because we do not have an SSL certificate at the moment. Can anyone provide guidance on configuring Axios in Nest JS to accept ...

Different hover effects for Material-UI [v0.x] RaisedButton

Is there a way to customize the hover styling of a Material-UI RaisedButton? It seems that the design guidelines dictate what happens on hover, but is there a method to modify the button's color and background-color specifically for when it is being h ...

Using jQuery, implement a functionality where a line break is added when the Enter key is pressed. Furthermore, the added

I have a text box where users can add cars to a list. Each car is entered on a new line, and when the user presses enter, jQuery adds a \n to move to the next line. However, when I collect this string, the \n characters are "hidden" and cannot b ...

Using JSON with Google Chart Tools

When referring to this example at , it is noted that the method data.addRows() requires a list of lists. A URI (/data/mydata.json) can be accessed to retrieve the following data: [["Canada", 66], ["Turkey", 10], ["Hungary", 23], ["Italy", 49]] Despite a ...

Generate HTML on the fly using Node variables

Utilizing Node.js with Express as the server, I have implemented a feature where users can upload .CSV files containing data. This data is then parsed and stored in a main array made up of arrays, with each line representing one array element. Currently, I ...

Customizing event colors in Full Calendar

My interactive calendar is created using : $('#calendar').fullCalendar({ height: 300, //............. events: jsonData, month: firstMonth }) I am looking to dynamically change the color of an event based on certain conditions ...

Tips for incorporating external routes into the routes index file

I am currently dealing with a users.js and an index.js file. users.js const express = require('express'); const router = express.Router(); const {catchErrors} = require('../handlers/errorHandlers'); const authController = require(&ap ...

What is the most efficient way to perform an array join in Node.js, akin to the speed of MongoDB's $

Looking to implement a $lookup function in Node.js similar to the $lookup aggregation in MongoDB. I have a solution in mind, but I'm unsure about its performance when dealing with larger arrays or bigger objects. let users = [ {userId: 1, name: ...

Submitting information via jQuery

https://i.stack.imgur.com/VU5LT.jpg Currently, I am working on integrating an event planner into my HTML form. However, I am facing difficulty in transferring the data ("meetup", "startEvent", "break") from HTML to my database. Using jQuery, I was able to ...

How can I ensure that reactive form fields are properly validated in Angular2?

I am currently facing issues with validating Reactive form field in Angular 2. I have implemented a custom validator for this purpose, but it seems like my approach is not yielding accurate results as some of the test cases are failing. If anyone has insig ...

Ways to transfer data from TypeScript to CSS within Angular 6

Trying to work with ngClass or ngStyle, but I'm struggling with passing the value. Here's my current code: strip.component.ts import { ... } from '@angular/core'; @Component({ selector: 'app-strip', templateUrl: &apo ...

Discover the sleek and modern concept of transparency in Microsoft's

I'm interested in incorporating Microsoft Fluent Design transparency into my webpage. Are there any CSS or other tools that can help achieve this design language? I want to enhance the look of my site with these elements. ...

What is the method for ensuring the banner image is visible behind the transparent navigation bar?

I recently used Bootstrap 4 to write the code below. In the image provided, I have outlined what my goal is with this code. Thank you! <style> div.jumbotron { background: #458392 url("img/banner.jpg") no-repeat right; ...

Poorly formatted code in VueJS when using Visual Studio Code

After reinstalling Windows and installing Visual Studio Code along with Prettier, I am facing an issue where the formatting is not up to par. Below is an example showcasing the difference between how it looks versus how it should look. Incorrect Formatting ...

Dealing with Angular.js $http intercept error "net::ERR_CONNECTION_REFUSED"

Currently, I am attempting to create a universal error handler for my website utilizing $http interceptors. However, it seems that the interceptors are not functioning as intended. I have set up interceptors for 'response' and 'responseErro ...

JavaScript nested function that returns the ID of the first div element only upon being clicked

I am facing an issue with a function that returns the id of the first div in a post when an ajax call is made. The problem is that it repeats the same id for all subsequent elements or div tags. However, when the function is used on click with specified ...

What is the process for storing a particular model in a designated collection within MongoDB's database?

I am working with three different models: user, teacher, student. All of these are stored in the database under the users collection. However, I want to save the student model in its own separate collection called students, instead of mixing it with the us ...

Ways to efficiently transfer multiple files from a server to a client using Express in NodeJS

I am working on a NodeJS server to transfer various files, such as images, css files, and js files, to clients. Currently, I have the following code snippet for sending individual files: app.get('/js/client.js', function (req, res) { res.sendF ...