CSS animation is designed to work with a single element

For my school project, I've been experimenting with creating a functional phone using HTML. To achieve this, I incorporated a JavaScript class as shown below:

document.querySelector(".app-content").classList.add("app-on");

The class .app-on alters the width, height, and font size of my div element with a built-in transition effect. However, while the font size smoothly transitions as intended, the width and height abruptly appear.

I am particularly focusing on the .app-content class. It is the first occurrence of that class within the code.

Here is the complete reference code:

<html>
    <head>
        <meta charset="utf-8">
        <link href="style.css" rel="stylesheet" type="text/css">
        <link rel="preconnect" href="https://fonts.gstatic.com">
        <link href="https://fonts.googleapis.com/css2?family=Inter:wght@900&display=swap" rel="stylesheet">
    </head>
    <body onload="startTime()">
        <!-- phone -->
        <div id="phone-border">
            <!-- screen -->

            <div id="phone-screen">
                <p id="time" style="font-weight: 600; font-size: 30px; float: left; color: white; padding: 10px;"></p>


                <div id="app-container">
                    <div class="app-wrapper" style="z-index: 10000;">
                        <img src="https://img.icons8.com/ios/452/coronavirus--v1.png" class="app-icon" style="left: 10%; top: 60%" onclick="openMA()">
                        <div class="app top-app left" href="#">Malware-Arten</div>
                        <div class="app-content" style="position: absolute; left: 0; color: black;">asdasdfasdfasdfasdf</div>
                    </div>


                    <div class="app-wrapper">
                        <img src="https://www.freeiconspng.com/thumbs/shield-png/shield-png-1.png" class="app-icon" style="right: 15%; top: 60%" onclick="openS()">
                        <div class="app top-app right" href="#">Schutz</div>
                        <div class="app-content"></div>
                    </div>


                    <div class="app-wrapper">
                        <img src="https://www.freeiconspng.com/thumbs/youtube-logo-png/hd-youtube-logo-png-transparent-background-20.png" class="app-icon" style="left: 10%; bottom: 17%" onclick="openYT()">
                        <div class="app bottom-app left" href="#">Youtube-Info</div>
                        <div class="app-content"></div>
                    </div>


                    <div class="app-wrapper">
                        <img src="https://www.designbust.com/download/1024/png/email_icon_transparent512.png" class="app-icon" style="right: 15%; bottom: 17%" onclick="openM()">
                        <div class="app bottom-app right" href="#">E-Mail</div>
                        <div class="app-content"></div>
                    </div>


                </div>


                <div class="blackscreen">


                </div>
            </div>
            <!-- /screen -->

            <!-- homebutton -->
            <div style="position: fixed;">
                <button class="pushable homebutton" id="hb">
                    <div class="front home-front">
                    </div>
                </button>
            </div>
            <!-- /homebutton -->

        </div>
        <!-- /phone -->
    </body>
    <script type="text/javascript" src="script.js"></script>
</html>

CSS styles are defined here:

@import url('https://rsms.me/inter/inter.css');
html { font-family: 'Inter', sans-serif; }

/* Remaining CSS styling unchanged for brevity */
...

JavaScript functions included:

// JavaScript functionality remains the same
...

Answer №1

When using document.querySelector
, keep in mind that it will only return a single element. For multiple elements, opt for document.querySelectorAll and pair it with a loop to achieve the desired outcome.

document.querySelectorAll(".app-content").forEach((element) => element.classList.add("app-on"));

Answer №2

In the world of div elements, their initial width and height are set to auto by default, preventing a seamless transition from an automatic measurement to a specific pixel value. To address this issue, consider including width: 0; height: 0; within the .app-content class.

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

Can you explain why this overtime total is not being calculated accurately?

Here's a scenario: A parking garage charges $5.00 to park for up to three hours. After that, they add $1.50 per hour for every additional hour or part thereof. The maximum charge within 24 hours is $18.00. We're assuming no car stays longer than ...

The method for transforming all headers into permalinks with jquery/javascript

I am looking for a way to transform all headers on a page into clickable permalinks using jQuery or JavaScript. Here is the HTML code: $('h3').each(function() { var id = $(this).attr('id'); if (id) { //Check if the element has a ...

Tips for optimizing a CSS file that includes the @page at-rule

When the CSS file for media='print' contains the @page directive, .myreceipt { @page { visibility: hidden; margin: 0 15px; } @page { height: auto; } } The ASP.NET MVC4 built-in minification tool does not ...

Inconsistency in the output of {%=file.name%}

I recently came across a drag and drop file upload system that I would like to incorporate into my website. In order to do so, I need to connect it with my database. However, I encountered an issue during the integration process. The problem I am facing is ...

When a client sends a GET request to the server, an error occurs due to the absence of 'Access-Control-Allow-Origin' header in

I am encountering an issue with my node/express js application running on localhost while making a 'GET' request to Instagram's api. The error message I keep receiving is: XMLHttpRequest cannot load https://api.instagram.com/oauth/authorize ...

Apply the AddClass function only when the data-id matches the specified id following the execution of an

I have an array containing HTML elements, and I want to add a class to the elements whose data-id matches the IDs retrieved from an AJAX call. Here is my code: function update_books() { var $bookIds = $(".js-book").map(function() { return $(this).dat ...

React JS progress circle bar is a simple and effective way to visualize

Currently, I am in the process of developing a progress circle bar that will function as a timer alongside sliders. Each slide is intended to have its own corresponding progress bar. While I have managed to create the bars individually, I am facing challe ...

Tips for integrating angular signature functionality using fabricjs in the latest version of Angular (Angular 11)

After struggling to make paperjs and the angular-signature library work together, I was at my wit's end. But then, I stumbled upon a different solution that proved to be much better. I realized that posting the solution under the appropriate question ...

Verify if session is in existence

Currently in the process of setting up my NodeJS and Express App, utilizing Passport for authentication through Google Sign In and Login. All functionalities work flawlessly when tested on localhost. The sign-in process is smooth, and upon checking, I can ...

Ways to handle a hidden element in Selenium Webdriver

Special features of this element:- <textarea id="txtSuffixTitle" class="form-control" tabindex="3" rows="2" placeholder="Suffix Title" name="txtSuffixTitle" maxlength="50" cols="20" style="display: none; visibility: hidden;">Suffix Title </text ...

Ways to incorporate HTML replacement within a function

In my application, non-IT users are responsible for creating and maintaining product pages for music CDs. These pages typically include information about the CD as well as a track-listing. We want to add an mp3 music player to each track, but we need to en ...

At what precise moment does the ng-checked function get executed?

When utilizing AngularMaterial, I have implemented ng-checked in the following manner: <md-list> <md-list-item ng-repeat="option in options"> <p> {{ option }} </p> <md-checkbox class="md-secondary" aria-label=" ...

The functionality of JQuery's `.on("click"... is sporadically functioning

I have a code block that dynamically generates elements and includes event handling. However, the event handling sometimes works and other times it doesn't. I'm not sure how to debug this issue. Can someone help me figure out what might be causin ...

Vue component doesn't update reactively until the template value changes

I have a child component in my Vue application that utilizes Vuex for managing certain values. Currently, when I trigger an action in the parent component, it should also trigger the child component. This is achieved by passing an active boolean prop to t ...

Unlock the full potential of integrating external APIs with Next.js

As a newcomer to NextJs, I am facing the task of making calls to an external Python API from my frontend. Upon discovering NextJs's integrated API feature through creating folders in the app directory, namely api/resource/route, I am wondering what th ...

Why isn't the jQuery colorbox popup appearing when triggered by the $.ajax() function?

I am currently facing an issue where I am trying to display a hidden colorbox popup using the $.ajax() method's success function, but it is not showing up. Interestingly, this had worked fine in a previous implementation where I used the data attribut ...

How to remove the black border on a material-ui button

I am currently working with the material-ui datepicker and buttons. Whenever I click on the datepicker icon to select a date or any of the buttons, I notice a black border appearing. How can I remove this black border from the design? https://i.sstatic.ne ...

Tips for executing several JavaScript files using the Node.js command line?

I am looking to launch 4 scripts using Node.js. myapp -script1.js -script2.js -script3.js -app.js -package.json .... .... I attempted to run them with the following commands: node script1.js && node script2.js && node scrip ...

What are the different ways to interact with the object retrieved from the onloadedmetadata event

Having trouble accessing a specific value in an object that is the result of the onloadedmetadata event. When I log the entire object using audioDuration, I am able to see and retrieve the respective value without any issues. However, when I try to access ...

Preventing the use of special characters in URLs using JavaScript

I have a treeview where I am dynamically adding nodes and attaching a JavaScript click function to each node. The issue is with the use of the escape function on the url values stored in thisFileNode.Value. Even after using the escape function in my code, ...