Height transition malfunctioning

Despite trying different methods such as Internal CSS, inline CSS, and JavaScript, I cannot get the transition effect "transition: height 1s ease-out;" to work. Currently, I am using the latest version of Chrome for testing purposes. It did work when I utilized separate functions like onmouseover to open the shutter and onmouseclick to close it.

<script>

function departmentShutter(){
    if(document.getElementById("departmentShutter").clientHeight === 100 ){
        document.getElementById("departmentShutter").style.height = "inherit";
    }
    else{
        document.getElementById("departmentShutter").style.height = "100px";
    }
}

function studentShutter(){
    if(document.getElementById("studentShutter").clientHeight === 100 ){
        document.getElementById("studentShutter").style.height = "inherit";
    }
    else{
        document.getElementById("studentShutter").style.height = "100px";
    }
}

</script>

Here is the relevant CSS code:

.dashboard{
    width: 100%;
    height: fit-content;
    position: fixed;
}
.dashboardContent{
    height: -webkit-fill-available;
    width: 100%;
    margin: 0px 0px 0px 0px;
    padding: 0px 0px 0px 0px;
    overflow-x: auto;
}
.department{
    height: 100%;
    width: 50%;
    left: 0px;
    display: inline-block;
    float: left;
    z-index: 0;
    position: fixed;
    margin-top: 100px;
}
.student{
    height: 100%;
    width: 50%;
    right: 0px;
    display: inline-block;
    float: left;
    z-index: 0;
    position: fixed;
    margin-top: 100px;
}
.departmentShutter{
    height: inherit;
    transition: height 1s ease-out;
    width: 50%;
    left: 0px;
    display: inline-block;
    background-color: #09d;
    float: left;
    z-index: 99;
    position: fixed;
}
.studentShutter{
    height: inherit;
    transition: height 1s ease-out;
    width: 50%;
    right: 0px;
    display: inline-block;
    background-color: #2d0;
    float: left;
    z-index: 99;
    position: fixed;
}
.departmentShutter span,.studentShutter span{
    font-size: 5em;
}
.rectangle{
    height: 200px;
    width: 200px;
    background-color: #78015d;
}    

Check out the corresponding HTML code below:

<div class="dashboard">
    <div class="dashboardContent">

        <div id="departmentShutter" class="departmentShutter cursorPointer disable-selection" onclick="departmentShutter()">
            <span class="center">Department</span>
        </div>
        <div class="department">
            <table>
                <tr>    
                    <td><div class="rectangle"></div></td>
                </tr>
            </table>
        </div>

        <div id="studentShutter" class="studentShutter cursorPointer disable-selection" onclick="studentShutter()">
           <span class="center">Student</span>
        </div>
        <div class="student">
            <table>
                <tr>    
                    <td><div class="rectangle"></div></td>
                </tr>
            </table>
        </div>

    </div>  
</div>

Answer №1

Transitions are effective only on values that can be converted to numbers and explicitly set on an element upfront, allowing the CSS rendering engine to determine the progression from the initial value to the final value. Since 'inherit' is not a numeric value, the transition fails to work.

To resolve this issue, replace height: inherit with height: 100% in both the .departmentShutter and .studentShutter classes as well as in the JavaScript code.

Furthermore, there is no necessity for separate functions for resizing two different div elements if they perform identical tasks but on different elements. These functions can be combined into one by utilizing the this keyword to identify which element needs resizing based on the triggered event.

Lastly, avoid using inline HTML event attributes like onclick to attach event handlers as this outdated practice hinders modern coding standards. Separate your JavaScript from HTML and adhere to contemporary methods of event binding for better code organization and maintainability.

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

App script: Extracting HTML form data from a web application

I have been trying to work on a script that involves taking input from an HTML form and processing that data in order to populate a Google Sheet. Unfortunately, I haven't had much success with it so far. Here is the code I have been working on: Index ...

Leveraging the power of promises to handle multiple requests

Recently, I encountered an issue while trying to use the request-promise module to check multiple websites simultaneously. When using Promise.all as intended, the promise would return with the first rejection. I sought a better way to execute multiple requ ...

Using identical filters for two ng-repeats causes issues in AngularJS, as it only seems to work in one of them

I am encountering an issue with my search box where I am attempting to filter two items, but only one is filtering correctly. Here is the code snippet in question: <!--this is the input--> <input type="search" placeholder="Sports finder" ng-mode ...

How do you properly bind multiple events in jQuery and then unbind just a few of them?

Is it possible to bind multiple events, then unbind a couple of them? This is what I'm trying to achieve: When hovering over the element, the background color changes and changes back when hovering out. But when clicking the element, I want to disabl ...

Set the image to be positioned absolutely on the entire screen

I'm trying to add a background image to the center of my webpage that spans the entire width of the browser. After finishing my page layout, I realized I needed to jazz it up by placing an image in the background. But, my attempt to center it and mak ...

What could be causing my Ajax request with dataType set to "jsonp" to encounter errors?

My code includes an Ajax call that looks like this: var baseurl = Office.context.mailbox.restUrl; var getMessageUrl = baseurl + "/v2.0/me/messages/" + rest_id + "?$select=SingleValueExtendedProperties&$expand=SingleValueExtendedPropertie ...

Using setInterval in React within an onChange event

I am facing a challenge where I need to set a setInterval inside an onChange event, which is typically done in componentDidMount. Currently, I have 2 dropdowns that filter data and then render a table. The dropdowns are controlled by their respective onCh ...

User-generated JSON Object with Date Information

I have created an API using Node.js/Express that receives input from a form including a date option in the request body. Currently, I am sending dates in the format YYYY-mm-dd, and I have also attempted using dd/mm/YYYY. However, when testing in Postman, ...

Exploring the Power of JQuery and Iterating with For-

I'm currently facing a small issue with my code. I need to retrieve information about each module when I display the hidden table row. The information is fetched from the page {modules/$moduleid}. While I understand how to utilize AJAX, my challenge l ...

Deactivate Bootstrap Button Pills and Activate Change with an Alternate Button

Seeking a solution for my multi-step form utilizing Bootstrap nav-pills. Currently, users can navigate through the steps without completing the required form fields first. I am looking to disable this feature and trigger content changes with a different bu ...

Troubleshooting the mysterious provider problem in Ui-router

I encountered this error message: "Module 'ui-router' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument." https://i.sstatic.net/o ...

Troubleshooting error message: "Unsupported import of ESM Javascript file in CommonJS module."

My project relies solely on CommonJS modules and unfortunately, I cannot make any changes to it. I am attempting to incorporate a library that uses ESM called Got library (https://github.com/sindresorhus/got). This is the snippet of my code: const request ...

Using type annotations is restricted to TypeScript files only, as indicated by error code ts(8010)

I encountered an issue with React.MouseEvent<HTMLElement> const handleOpenNavMenu = (event: React.MouseEvent<HTMLElement>) => { setAnchorElNav(event.currentTarget); }; const handleOpenUserMenu = (event: React.MouseEvent<HTMLElement ...

Looking for assistance with changing the class of a span when a radio button is selected

I'm facing an issue with toggling the class of a <span> when a radio button is clicked. <html> <head></head> <style type="text/css"> .eHide { display:none; } </style> <script type="text/javas ...

Tips for showcasing content by hovering over buttons with the help of Bootstrap3 and Jquery

My code and fiddle are currently set up to display buttons when hovered over, but I want to modify it so that only the relevant button is displayed when a specific text is hovered over. For example, if "Water" is hovered over, only the button for Water sho ...

What methods does selenium use to compare elements?

Recently, a new method called equals() was introduced in the latest version of Protractor for an ElementFinder object. This method essentially utilizes the WebElement.equals() function from WebDriverJS: return webdriver.WebElement.equals(this.getWebElemen ...

submit a new entry to add a record to the database

Hey there, I recently started learning PHP and JS and I'm trying to insert a row into a WordPress database table. I need to get the information needed for insertion from another table, but I'm facing an issue with the PHP file as it's not in ...

Leveraging webpack for requiring modules in the browser

I've been attempting to utilize require('modules') in the browser with webpack for the past couple of days, but I could achieve the same functionality with browserify in just 5 minutes... Below is my custom webpack.config.js file: var webp ...

What are some strategies for postponing the execution of a basic function for an

Whenever I develop microservices, I often come across situations where one function contains multiple other functions. For instance: functionA(); functionB(); functionC(); return json({status: processed}); All the functions within this block are synchro ...

group items into ranges based on property of objects

I've been grappling with this issue for far too long. Can anyone provide guidance on how to tackle the following scenario using JavaScript? The dataset consists of objects representing a date and a specific length. I need to transform this list into a ...