Conceal element with transparent overlay without affecting the background

Looking to add animation to a snippet where the login menu rolls out? Consider two methods: adjusting the left position of the login menu or using another div on top to slowly reveal the login menu after moving it. The challenge lies in maintaining transparency while covering one div with another. Any suggestions on achieving this seamlessly with CSS, JS, or jQuery?

// JavaScript code for handling the login animation
const accountImg = document.querySelector("#login");
let accountOpen = 0;

document.querySelector("#login").addEventListener("click", function () {
    if (accountOpen == 0) {
        // Open the login menu
        document.querySelector(".login-wrap").classList.add("active");
        accountOpen = 1;
        // Show username field
        document.querySelector("#username").style.opacity = "1";
        document.querySelector("#username").style.visibility = "visible";
        document.querySelector(".label-username").style.visibility = "visible";
        document.querySelector(".content-username").style.visibility = "visible";
        
        // Show password field
        document.querySelector("#password").style.opacity = "1";
        document.querySelector("#password").style.visibility = "visible";
        document.querySelector(".label-password").style.visibility = "visible";
        document.querySelector(".content-password").style.visibility = "visible";

        // Show login button
        document.querySelector(".login-wrap .login-btn").style.opacity = "1";
    } else {
        // Close the login menu
        document.querySelector(".login-wrap.active").classList.remove("active");
        accountOpen = 0;
        // Hide password field
        document.querySelector("#password").style.opacity = "0";
        document.querySelector("#password").style.visibility = "hidden";
        document.querySelector(".label-password").style.visibility = "hidden";
        document.querySelector(".content-password").style.visibility = "hidden";

        // Hide username field
        document.querySelector("#username").style.opacity = "0";
        document.querySelector("#username").style.visibility = "hidden";
        document.querySelector(".label-username").style.visibility = "hidden";
        document.querySelector(".content-username").style.visibility = "hidden";

        // Hide login button
        document.querySelector(".login-wrap .login-btn").style.opacity = "0";
    }
});

Answer №1

Instead of using two separate divs, consider this alternative:

Try adding a transition to the class "login-wrap" like so:

transition: width 1s ease-in-out

Simply adjust the width of your "login-wrap" element from 0px to the desired width whenever a user clicks a button

Ps: don't forget to set overflow to hidden as well

EDIT: Check out this informative post on implementing transitions with height/width "auto": Here

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

Utilizing a hidden file-input, IE10 is able to transmit a FormData object via ajax

I'm encountering difficulties when trying to send a form that includes a display:none file-input via ajax. It works fine in Chrome (46.0.2490.71), but not in IE10 (10.0.9200.17492). I've tried various solutions without success, and it's cruc ...

bootstrap thumbnail displayed without a border

I have decided to incorporate Bootstrap into my latest project: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS ...

Conceal the input field prior to making a selection from the dropdown menu

I have implemented a drop-down menu for selecting dependencies, similar to how it functions in JSFiddle. $('#user_time_zone').on('change', function() { dateCalender = $(this).val(); if (dateCalender == 'Single Date') { ...

Sort array of objects alphabetically and move objects with value to the beginning

I have a dataset that consists of different arrays of objects. When I log myData, the output looks something like this: [ { name: 'Cdb', image: 'xxx', coll: 'xxx' }, { name: 'Bcd', image: &a ...

Problem with jQuery offset: SWF position remains unaffected

I attempted to create a code that would position an SWF file on top of an HTML button using jQuery's offset function to determine the coordinates. However, despite my efforts, the SWF does not appear to move as intended. var offset = $("#button").off ...

Is it possible to trigger the onNewRequest property when the onBlur event is fired for AutoComplete in Material-UI?

Currently, I am utilizing Material-UI and making use of the onNewRequest property in the AutoComplete field. However, the onNewRequest only triggers when Enter is pressed or when a value is selected. I am interested in calling the onNewRequest even when ...

Using Jquery's click function is unable to display the information stored in the database

I'm encountering an issue with my Jquery onclick event in my form. I'm unable to display data from the database. For example, when I choose a category like "heart", the doctors associated with that category should be displayed. However, if I use ...

During my JavaScript coding session, I encountered an issue that reads: "Uncaught TypeError: $(...).popover is not a function". This

Encountering an issue while trying to set up popovers, as I am receiving this error: Uncaught TypeError: $(...).popover is not a function. Bootstrap 5 and jQuery links are included in the code, but despite that, the functionality is still not operational. ...

Persistent banner designed to accompany blog posts

I've been attempting to insert a banner ad that runs along the left side of my blog post. Unfortunately, all my efforts so far have caused it to display above the content, pushing the blog post down the page. You can view the live link here. Here i ...

Troubleshooting: Why isn't my Vue v-for list updating when using v

I have a basic application that retrieves data from an API and displays the array on the screen using a v-for loop. The array is structured like this items : [{id : 1, quantity: 2}, {id: 2, quantity: 3} ...] The loop is set up like this <div v-for=&qu ...

Comparison between an empty div and a div containing text with the inline-block property applied

Curious about why this phenomenon is occurring. CSS div { display: inline-block; margin-right: 2px; width: 20px; background-color: red; } Empty div <div style="height:20px;"></div> <div style="height:40px;"></div> &l ...

Altering row heights in Bootstrap

Here's the code snippet I'm working with: <body> <div class="container-fluid h-100 border"> <div class="row h-50"> <div class="col-sm-12 bg-danger">Row1</div> </div> < ...

The text-overflow property with ellipsis functionality appears to be malfunctioning in Internet Explorer when applied to input elements, yet functions

Having an issue with the MS IE (version 11) when using the text-overflow: ellipsis; property for an input field. It appears that this specific property is not working properly in this browser. If anyone has any suggestions or solutions, it would be greatl ...

"Utilize an AJAX call to dynamically retrieve and add results for every PHP loop

I currently have a functional AJAX request that calls a PHP file with some looping actions. Depending on certain parameters, the request can take several minutes to complete, which is not ideal for user experience. How can I modify my code so that results ...

Incomplete data was retrieved from the localStorage

I am currently in the process of developing a mobile application using Phonegap version 1.4.1. I have encountered an issue on iOS (running on version 5.1) where the app fails to load all data from localStorage. Upon first use of the app, I set a flag in l ...

Reloading Vue router view following a successful AJAX request

Currently, I am working with a Vue Router set up that consists of two components: a list view and a detailed view. The challenge I am facing is when the data is fetched via ajax, the non-router list updates successfully but the router view does not reflect ...

Formatting code within an HTML document

I am attempting to customize a stock widget that I obtained from financialcontent.com. My current approach involves using Bootstrap for styling purposes. To incorporate the widget into a div, I found it necessary to embed the script directly within the HT ...

Managing the re-triggering of a function within useEffect upon the user clicking the "Back Button" in a React application

Is there a way to prevent the loadUserPosts() function from being called again when the user clicks the 'back button' on their browser? It seems like the isLogged useState is being changed when the back button is clicked. The loadUserPosts funct ...

Implement jQuery to toggle a class on click for added functionality

I am attempting to create a box that changes color when clicked. When the box is first clicked, it will turn red by adding the class red, and if clicked again, it will change to blue. The colors alternate with each click, but I am unsure of how to achieve ...

Vue 3 - Compelled to utilize any data type with computedRef

Recently, I've been diving into Vue/Typescript and encountered a puzzling error. The issue revolves around a class named UploadableFile: export class UploadableFile { file: File; dimensions: Ref; price: ComputedRef<number>; ... constr ...