Initiate the height animation starting from the bottom rather than from the top

As the title suggests, I am looking to initiate the height animation starting from the bottom rather than the top. While this question has been asked before in places such as here, it does not provide the solution I am seeking and involves the use of jQuery which I prefer to avoid.

I have set up a simple jsFiddle demonstration of a sliding box.

Here is my code:

function addClass() {
    const box = document.querySelector('.box');
    box.classList.toggle('show');
}
.container{
  height: 400px;
  width: 200px;
  border: 2px solid black;
}

.box{
  height: 0;
  overflow: hidden;
  background: black;
  transition: 0.4s;
  transform-origin: bottom;
} 

.box.show{
  height: 400px;
}
<div class="container">
  <div class="box">

  </div>
</div>

<button onclick="addClass()">
  click me
</button>

My desired result is for the box to slide up from the bottom instead of the top.

Answer №1

Can this be of assistance?

function toggleClass() {
const container = document.querySelector('.container');
  container.classList.toggle('expand');
}
    .wrapper{
      height: 300px;
      width: 150px;
      border: 1px solid #333;
      overflow: hidden;
    }

    .container{
      height: 100%;
      position: relative;
      top: 50%;
      background-color: lightgray;
      transition: top 0.3s;
    }

    .container.expand{
      top: 0;
    }
<div class="wrapper">
  <div class="container">
    
  </div>
</div>

<button onclick="toggleClass()">
  Show me
</button>

Answer №2

To initiate your animation from the bottom of the webpage, simply apply the following CSS:

position: absolute;
 bottom: 0px;

This initial styling will position the div or element at x:0 y:0 coordinates. By setting bottom: 0px, it will be pushed to the lowest Y value possible on the page, effectively placing it at the bottom.

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

Enhance your navigation bar with hover styles in React Router Dom v6

I'm having an issue with my navbar where the active styles are overriding the hover state. I want to maintain my hover state styles even on the active nav link. How can I achieve this? Here is what's currently happening: Active nav styles (look ...

Guidelines for sending an array from a Laravel Controller through AJAX and generating a button based on the received data

Before making a selection, I click on the Color button: <form class="form form-variant"> {{ csrf_field() }} <button type="submit" class="btn btn-success che ...

Notify the chat when a new record is added to the database

Alright, so here's the issue I'm facing. I created a chat application using PHP and MySQL, but I noticed that when I enter text, it doesn't update in the other window automatically. This led me to experiment with iframes, which I found much ...

Ways to maintain the collapsed sidebar state during redirection to a new page

I'm currently working on an admin dashboard and I want the sidebar to remain collapsed even when transitioning from one page to another. Initially, I prefer it to be expanded but after clicking the hamburger toggle button, it collapses. However, I don ...

A step-by-step guide on showcasing the content from a textfield onto a dynamic column chart

How can I show the value from a text field in a column chart? I found the code for the chart on this website(). I tried using the code below, but nothing happens. Can someone please assist me? <script> window.onload = function () { ...

What's the best way to show floating point numbers in a concise format while also maintaining the ability to perform calculations within this Vue app?

I'm currently developing a compact calculator application using Vue 3 and implementing some custom CSS. For the most part, everything seems to be functioning correctly, except for when the results are long numbers that extend beyond the display limit ...

Combining two rows into a single cell using AG-GRID

Currently, I am utilizing AG-GRID for angular in my code. Within this grid, I have two columns available - Account.Name and Account.Surname. My goal is to display the values from these two columns within a single cell. To achieve this, I attempted the meth ...

I am unable to close the hamburger menu by clicking on it

I am facing an issue with the hamburger icon functionality. The menu opens when I click on it, but it is not getting closed when clicked again. I have been trying to debug the code, but I can't figure out what's causing the problem. If anyone has ...

The inconsistent sizing and spacing between browsers is causing some strange issues for me

I can't shake this feeling that it should be so straightforward. I'll include screenshots from Chrome, Firefox, and IE 11 to illustrate. First things first, it's just a basic login form with email and password fields centered both verticall ...

Text displayed in Ajax tab container is not accurate

My website features an ajaxToolKit:TabContainer with a total of three tabs that are populated by each Product in some capacity (Description, Additional Information, Reviews). Additionally, there are three other tabs that are dynamically generated and added ...

Too much gap between the span and the border's bottom

Occasionally, there seems to be an odd gap between the span and the bottom border. This issue is particularly noticeable on mobile devices. You can view a screenshot of the problem here: Code .heading { text-align: center; border-bottom: 2px solid ...

Manage the element that should receive focus() after tab is pressed from an input field

On my webpage, there is a variety of elements such as inputs and anchors. I need to specify which input field the browser should move focus to when I press the tab key while on an input. Currently, pressing tab from one specific input takes me to a menu i ...

Leveraging WordPress as a landing page integrated with a Silverlight backend

Currently, I am a web developer working on a project for a WordPress landing page that will eventually direct users to an all-Silverlight page. However, my programmer is claiming that this cannot be accomplished due to conflicts between PHP and Silverlight ...

Troubles with retrieving Array data for a JavaScript column chart

I am currently developing a Flask app in Python and utilizing render_template to send back 2 arrays, "names" and "deals", to my HTML file. I have confirmed that these arrays are working correctly based on the code snippet below that I tested, which display ...

Creating responsive images with Bootstrap 5

1 I am currently using Bootstrap 5 to develop a website and encountering an issue with getting images to move above text in the feature and mission sections on mobile or tablet screens. Previously, I was able to achieve this effect using the following cod ...

Creating an Android application that integrates HTML styling efficiently

I currently have a social networking site with a mobile web version, and my goal is to package that view into an Android app and potentially enhance it with a custom splash screen. Essentially creating a branded browser window. If you have any tips or adv ...

Discover an effective way to display Ajax search results above a different div element!

I am having trouble with positioning my search results on top of other divs. To see the issue, you can watch the screen recording by clicking on this link: https://drive.google.com/file/d/1kU_vl2ZAmSCok0pxnTTvY hacxqcZZ9m_/view?usp=sharing These are the s ...

Angular 6: Issue with displaying data on the user interface

Hello! I am attempting to fetch and display a single data entry by ID from an API. Here is the current setup: API GET Method: app.get('/movies/:id', (req, res) => { const id = req.params.id; request('https://api.themoviedb.org/ ...

Failed to add a new entry to the Sharepoint 2013 List

Having trouble saving an item to a SharePoint list using Knockout.js and REST. In my Ajax POST request, I've used ko.toJSON but the entry doesn't show up in the SharePoint list. It's possible that I'm passing the wrong parameter value. ...

Why is the JSfiddle tutorial not functioning properly in other environments, generating the error "Property 'clientHeight' cannot be read of null"?

I've been diving into a THREE.js tutorial to learn how to set up a basic scene and add animation keyframes triggered by scrolling. Everything worked smoothly in the fiddle, but when I tried to transfer it to my website, I encountered this persistent e ...