Animate the opening and closing of a div element

A form is set up for editing.

Within this form, there are 2 separate divs.

The first div is labeled editForm, which displays the form for editing, and the second div is labeled infos, which shows the details of this form.

My goal is to have the infos section hidden on mobile or tablet devices and display a button to open it. Currently, the button successfully hides the infos section, but I want to add an animation to the show and hide functionality.

View Demo

How can I achieve this?

HTML:

<div class="container">

    <div id="editForm" class="editForm">
        <form>
            <div class="items">
                <label>name</label>
                <input>
            </div>
            <div class="items">
                <label>name</label>
                <input>
            </div>
            <div class="items">
                <label>name</label>
                <input>
            </div>
            <div class="items">
                <label>name</label>
                <input>
            </div>
        </form>
    </div>
    <div id="infos" class="infos">
        <ul>
            <li>first</li>
            <li>second</li>
        </ul>
    </div>
</div>
<div id="mySidenav" class="sidenav">
    <a (click)="showHideInfo()">Open</a>
</div>

CSS:

p {
    font-family: Lato;
}
.container{
    display: flex;
}
.editForm{
    border: 1px solid red;
    width: 60%;
    display: flex;
    justify-content: center;
}
.infos{
    border: 1px solid red;
    width: 40%;
    display: flex;
    justify-content: center;
}
@media (max-width: 768px)
{
    .infos{
        display: none;
        width: 0;
    }
    .editForm{
        width: 100%;
    }
}
#mySidenav a {
    position: fixed;
    background-color: #4caf50;
    right: 0px;
    -webkit-transition: 0.3s;
    transition: 0.3s;
    top: 50%;
    display: flex;
    padding: 3px;
    width: 39px;
    text-decoration: none;
    font-size: 20px;
    color: white;
    border-radius: 5px 0px 0px 5px;
}

#mySidenav a mat-icon{
    margin-right: 10px;
    margin-top: 6px;
}

#mySidenav a:hover {
    right: 0;
}

#about {
    top: 20px;
    background-color: #4caf50;
}

This is the code that triggers the show or hide functionality for the infos section when the button is clicked:

showHideInfo(): void {
    if(this.sidebarShow)
    {
        var editorEdit = document.getElementById('editForm');
        editorEdit.style.visibility='visible';
        editorEdit.style.width='100%';
        var actionInfo= document.getElementById('infos');
        actionInfo.style.display='none';
        actionInfo.style.width='0';
        this.sidebarShow=!this.sidebarShow;
    } else {
        var editorEdit = document.getElementById('editForm');
        editorEdit.style.visibility='hidden';
        editorEdit.style.width='0';
        var actionInfo= document.getElementById('infos');
        actionInfo.style.display='block';
        actionInfo.style.width='100%';
        actionInfo.style.animation="showInRight";
        this.sidebarShow=!this.sidebarShow;
    }
}

Answer №1

To make this happen, apply a transition effect to the .editForm like so:

.editForm{
  transition: width 0.3s ease;
}

Give it a go and let me know if this meets your needs.

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

Angular 2- Custom input forms sourced from various components for enhanced user experience

I am currently working on creating an angular 2 form using template-driven and I want to reuse a custom input that I have created. My main component structure looks like this: <form (ngSubmit)="onSubmit(f.value)" #f="ngForm"> <custom-in ...

UI-router issue: UI view and links not functioning properly

Recently, I decided to implement ui-router for Angular in my project. After adding the following code snippet to my app module within the app.js file: angular .module("ngClassifieds", ['ngMaterial', 'ui.router']) .config(function($md ...

Unfortunately, we encountered an AJAX error while trying to access data from the website datatables.net. You can find

I'm currently working on adding data to a datatables.net datatable using a JSON response, following the example provided here. To achieve this, I am making use of an AJAX call to fetch a JSON response from a database. After obtaining the data, I uti ...

Trigger an alert message upon clicking a button within CK Editor

Is it possible to trigger an alert message using ckeditor when a specific button is clicked? Below is the code snippet for reference: $(document).ready(function () { $(".cke_button__bold").click(function () { editor.on("CKEDITOR.cke_butto ...

Troubleshooting issue: How to effectively extract route params in Angular using switchMap

I've been following a tutorial on how to retrieve route parameters in the Angular Routing documentation. Initially, I successfully retrieved the route parameters using subscribe. this.getRouteParams$ = this.route.params.subscribe(params => { // ...

Adding the output of a UNIX command to a div container

I am currently working on creating a UNIX web-based terminal for educational purposes. My progress so far includes setting up a text box and displaying the output, similar to this: <?php $output = shell_exec('ls'); echo "<pre>$output< ...

Discover the Phillips Hue Bridge within the operational web application on a separate network

Utilizing the node-hue-api package on a Node.js/Express server to interact with the Hue API, I've developed an admin section of a website exclusively accessible to me for controlling my Hue lights. The functionality works seamlessly in my local develo ...

`Observing a nearby external library while running the application`

I am currently working on a main app alongside some independent libraries. To incorporate changes from the library into the main app, I have been including the .tgz file in the main app's package.json. However, this process requires me to build and pa ...

Adding properties to Vue.js component in the script section without affecting rendering

How can I import component A with props and pass it to another component B for rendering? import MyComponent from '/MyComponent.vue' computed: { compnt: function () { var comp = MyComponent // How can I set props to MyC ...

Tomcat encounters difficulty accessing the JavaScript directory

Seeking assistance with my first question regarding Angular tutorials. When I deploy to test the script, I encounter an HTTP 404 error. I have tried various solutions suggested for similar issues without success. It appears to be a path problem as the ang ...

extracting information with beautifulsoup

Currently, I am diving into BS4 to enhance my skills and expertise. My goal is to scrape various tables, lists, and other elements from well-known websites in order to grasp the syntax. However, I am encountering difficulties when it comes to formatting a ...

Exploring the capabilities of chromaprint.js within a web browser

I'm currently in the process of developing a music streaming platform and I'm looking to include the chromaprint.js library for deduplication purposes. In my workflow, I utilize browserify and gulp. Despite the fact that the library claims it ca ...

Text-color in the v-tooltip

Is there a way to change the text color of v-tooltips components without affecting the tooltip background color? I attempted to inspect the element, but the tooltip only appears on hover, making it impossible to inspect. Below is the code snippet: < ...

Interactive sidebar component with navigation and animated section markers

For weeks, I've been attempting to create a navigation sidebar similar to the ones shown in these images: Even though getbootstrap.com/components offers appealing navigation sidebars, I have not found a built-in component in their library. This has m ...

Steps for adding an npm dependency as a peer dependency:

Is there a way in npm to install dependencies as peer-dependencies similar to the yarn option --yarn, rather than manually adding them? For instance: "peerDependencies": { "@angular/core": "^7.0.0" } Update: Further clarifi ...

Having trouble with input functionality on iPad due to a CSS, LI, div, or clipping issue?

https://i.sstatic.net/muMSG.png One challenge I am facing is related to several inputs housed within an LI and div that are sortable using jQuery. The problem arises specifically on the iPad when attempting to click into the inputs to enter information - ...

I am attempting to integrate the file path of my images using PHP

Let me start off by showing you the file structure of my website. File Structure Of my website In order to organize my code, I created a header file named header.html.php which contains all the necessary elements for the header, including an image tag fo ...

Guidelines for populating data with an array

I have the following array: const dataArr = [[15, 14, 5], [16, 10, 2], [17, 6, 13], [18, 4, 8], [19, 7, 4]]; Now, I am populating another array using the above data as shown below: for (let i=0; i<dataArr.length; i++){ newData.push(dataArr[i]); ...

Display or conceal several elements using JQUERY/HTML upon hovering

Here is the current progress: <div style="position: relative;"> <a href="#games"> <div class="sidenavOff"> <img src = "images/card_normal.png" /> <img src = "images/category_icons/icon_games.png" style = "position: a ...

Tips for setting the height of a div within a td to be 100%

I am struggling to make the orange divs in this example stretch out to match the height of the enclosing td element without explicitly setting the parent's height. I have tried using display: flex and align-items: stretch, but I can't seem to ach ...