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

ReactJS encountering issue with sending POST request, blocked by CORS preflight options

Every time I try to send a POST request to the server, it always responds with an unexpected OPTIONS. My login application built with React and Apollo is experiencing issues. Upon form submission, a mutation should be sent to the server via a POST request ...

Check to see if the date selected from the HTML5 date picker is in the past compared to the current date

When working with HTML, I have a task where I need to input a date (mm/dd/yyyy) using the new HTML 5 date picker: <input name="date" type="date"> My goal is to validate whether the date entered is older than today's date. $this_date = $_POST ...

Using local storage with github sites can lead to some unexpected and peculiar behavior

Currently, I am working on a simple clicker game using HTML and JavaScript. To store the variables money and taxCollecters, I have implemented local storage. However, I am encountering strange issues when trying to use the save and load buttons on the Gi ...

Collecting, gathering content repeatedly

Hey there, just checking in. I'm currently working on extracting information related to CEO Pay Ratio and compiling links to this section for processing by a function. My goal is for the function to capture content starting from a specified tag and en ...

Make sure that the iframe loads the next page with enough force to break out

My dilemma involves an iframe that loads the new tab page. When a user clicks on the thumbnail, it opens within the iframe. My goal is to have any subsequent load in the iframe redirected to window.top. Is there a way to achieve this without manually setti ...

Ensuring that the text input is perfectly lined up with the submit button

Is there a way to solve this discrepancy? Solution: https://jsfiddle.net/6q352ysx/59/ The elements are currently the same height, but not aligned properly. https://i.stack.imgur.com/ajVyJ.png Which alignment option should I use? Option 1: vertical-ali ...

What are the benefits of utilizing the useStyles MaterialUI function instead of traditional CSS?

As I develop my MERN application, I am utilizing Material UI components along with inline attributes. However, I find myself questioning the necessity of creating a JavaScript file just to import the makeStyles function, which essentially outputs an obje ...

The MUI component with hideBackDrop={true} is preventing me from clicking outside of the Drawer component to close it

I implemented a Drawer component which opens when an icon on the Map is clicked. The drawer menu appears along with a backshadow that drops over the map. Interestingly, clicking on the map while the backshadow is displayed closes the drawer without any i ...

Ways to remove code from production during build process?

Is there a way to omit typescript code from getting bundled by webpack during build process? Let's say I have the following line of code in my app.ts file (a nodejs application): const thisShouldNotBeInProductionBundleJustInDevBundle = 'aaaaaaa ...

Obtain array buffer from NodeJS to capture frames from a video file

My current goal is to extract frames from a video in node without relying on a video tag. I am utilizing openvg-canvas for this task, which allows me to print images and use the canvas API functionalities successfully. The challenge lies in the fact that ...

Tips on choosing vml elements using jquery or vanilla javascript

I am trying to select a VML element using jQuery without relying on 'id' or 'class', but my attempts have been unsuccessful so far. <v:oval id="vmlElement" style='width:100pt;height:75pt' fillcolor="red"> </v:oval> ...

Using ES6 without the need for jQuery, populate a select element with JSON data using Javascript

I have a json-formatted dataset that I want to incorporate into my select options. Here is the data: { "timezones": { "country": "Africa", "tz": "Africa/Abidjan" }, { "country": "America", "tz": "America/ ...

Prevent the row height from fluctuating following the fadeOut() effect

Currently, I am facing an issue with two elements on my page: .start_over_button and .speed_buttons. In CSS, the .start_over_button is set to display: none, and in my JavaScript code, I have it so that when .speed_buttons are clicked, they fade out and the ...

"Executing a query on Angular Firestore using the where clause fetches all documents from the

I am encountering a perplexing issue with my angular app that is connected to Firestore. Despite following the documentation closely, when I query for documents in a collection based on a specific condition, the array returned contains every single documen ...

The error occurred while trying to cast the value of "{{Campground.name}}" to an ObjectID. This value, which is of type string, could not be converted to an ObjectID at the path "_id" for

const express = require("express"); const session = require("express-session"); const cookieParser = require('cookie-parser') const mongoose = require("mongoose"); const { Campground, User, Review } = require(" ...

Personalizing Material-UI's select component: A step-by-step guide

Desired Outcome: https://i.stack.imgur.com/khNHn.png https://i.stack.imgur.com/dQzVz.png Progress So Far: https://i.stack.imgur.com/CUixn.png Struggling to Position SVG Icon Next to Text: https://i.stack.imgur.com/4GFtA.png Issue with Black Line Whe ...

Dynamically assigning a name to a variable through code

Is there a quicker way to complete these 100 tasks? variable_1 = 1; variable_2 = 2; variable_3 = 3; ... variable_100 = 100; I attempted to use the following code: for(var i = 1; i <= 100; i++) { variable_ + i = i; } However, I encountered an e ...

Interact with various contenteditable sections by navigating with the arrow keys

I have a challenge with multiple <p contenteditable="true"></p> elements on my page. I am seeking a solution to enable the use of arrow keys to navigate seamlessly across these separate elements as if they were one cohesive editable element. F ...

Tips for sending the setState function to a different function and utilizing it to identify values in a material-ui select and manage the "value is undefined" issue

I am currently utilizing a Material UI select component that is populated with data from an array containing values and options. Within this array, there exists a nested object property named "setFilter". The setFilter property holds the value of setState ...

What is the best way to show a nested div element within a v-for loop in Vue.js?

One interesting feature of my coding project is that I have an array nested within another array, and I iterate through them using two v-for loops. The challenge arises when I try to display a specific div in the second loop only upon clicking a button. ...