The appearance of the pop-up mask is displayed at lightning speed

Check out the demo here

Here is the HTML code:

<div class="x">
</div>

<input class="clickMe" type="button" value="ClickMe"></input>

This is the JS code:

  $(".clickMe").click(
            function()
            {
               $('.x').show().css('top',0).addClass("mask"); 
            }
        );

And here is the CSS styling:

.x
    {
        width: 200px;
        height: 200px;
        border: 1px solid #0f0f0f;
        position: relative;
        top: -210px;
        transition: all 1s ease 0s;
        float: right;
        margin-right: 20px;
    }
    .mask::before
    {
        position: fixed;
        top:0;
        left: 0;
        z-index: -1;
        width: 100%;
        height: 100%;
        content:"";
        background-color: #777;
    }
    .mask::after
    {
        content: "";
        background-color: #fff;
        opacity: 0.5;
        width: 100%;
        height: 100%;
        z-index: -1;
        position: absolute;
        top: 0;
        left: 0;
    }

    .mask
    {
        transition: all 2s ease 0s;
    }

After clicking the button in the fiddle, the mask appears first and then the popup slowly due to the transition effect. How can I make them both transition at the same speed? Are there any other better methods to show both the popup and mask smoothly?

Do you have any suggestions or ideas?

Answer №1

If you want to achieve a fade-in effect, consider adding a separate div element for the transition as demonstrated in this example.

Here's how you can set it up:

<div class="overlay"></div>

Then use the following JavaScript code:

$('.overlay').addClass('visible');

And style it with CSS like this:

.x {
    width: 200px;
    height: 200px;
    border: 1px solid #0f0f0f;
    position: absolute;
    top: -210px;
    right: 0;
    transition: all 1s ease 0s;
    margin-right: 20px;
    z-index: 10;
    background-color: #fff;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, .5);
    transition: all 1s linear;        
    opacity: 0;
}

.visible {
    opacity: 1;
    z-index: 5;
}

To see how the overlay works, check out this updated demo where the mask covers everything except the popup: updated example

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

When a Vue.js Directive is inserted or bound, it actually takes precedence over the click event

Imagine having multiple dropdowns or elements on the page that all utilize a directive called "closable". This directive triggers an expression if the element clicked is outside of the element using the directive. The intended behavior is that when clicki ...

Popovers in Bootstrap 4 do not have clickable Custom Forms

I find it strange that in Bootstrap 4, only custom forms are not clickable in the Bootstrap popover. It's interesting how default forms in Bootstrap 4 work just fine. Any suggestions on how to resolve this issue? Below is my code. Thank you for you ...

Struggling with uploading files in AngularJS?

Below is the code snippet from my controller file where I aim to retrieve the values of various input elements (name, price, date, image) and store them in an array of objects... $scope.addBook = function(name, price, date, image) { name = $scope ...

Having trouble getting Vue-Select2 to display properly in Vuejs?

After setting up the vue3-select2-component and following their instructions, I encountered an issue where the component was not displaying in the output on the html page, even though the code for it was present in the source code. For context, I am using ...

Creating equal-sized borders for symbols of varying sizes: a step-by-step guide

Utilizing Font Awesome icons along with their fa-border style: <i class="fa fa-twitter fa-5x fa-border icon-blue"></i> <i class="fa fa-question fa-5x fa-border icon-grey"></i> The border size created varies based on the symbol siz ...

Uploading Files within Angular FormArray

I am facing an issue with my formArray which contains file upload inputs in each element. Whenever I upload an image in one input, it changes the values of other file inputs in different rows. https://i.stack.imgur.com/3haZW.png Current Behavior: Uploadi ...

Displaying the specified item within an array using AngularJS

My application features a group of 'players' each with their own unique attributes that I want to showcase within a modal window and cycle through. The user interface is structured like this: <!-- Score Round Modal --> <div class="mo ...

Troubleshooting issues with Bootstrap Accordion functionality within a React environment

After copying and pasting the Accordion code directly from Bootstrap, I'm facing an issue where the style is not consistent and the functionality isn't working as expected. Snippet from About.js: import React, { useState } from 'react' ...

Unable to retrieve the post value from the Ajax Request due to a null reference

When using Ajax to send values via the Post method, I encountered an issue. $.ajax({ url: 'api/login', contentType: 'application/json', type: 'POST', data: { sessionId: '123', jCrypti ...

Maintaining the footer and bottom section of the webpage

I am facing an issue with the footer on my website . I want the footer to always stay at the bottom of the page, even when I dynamically inject HTML code using JavaScript. The footer displays correctly on the main page , but it does not work as intended on ...

Efficiently refine your search using the combination of checkboxes and dropdown menus simultaneously

I am currently in the process of creating a highly sortable and filterable image gallery that utilizes numerous tags. The inspiration for this project stems from a similar question on Stack Overflow regarding dropdown menus and checkboxes. You can view the ...

Utilize CSS styling on dynamically loaded HTML content

I am working on a project similar to the StackOverflow editor. I am fetching markdown text, converting it to HTML, and then displaying it in a preview area. However, when I try to style the injected HTML elements using CSS, the styles are being ignored. Up ...

Interacting div elements with jQuery's dynamic content

I am searching for a way to populate a div with content based on my click selection. To begin, I create a dynamic table like the one below: user name total hours worked button(unique id fetched from database) user name total ho ...

Utilizing Dojo widgets in Xpages

I'm having trouble applying CSS to certain dojo elements within my Xpage. Here is the CSS style sheet I am using: .formFields { color: rgb(5, 56, 107); font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant: nor ...

By incorporating JavaScript, clicking on an image will trigger a shift in the position of a different element

Just starting out with JavaScript and experimenting with creating an event where clicking on an image triggers the movement of another hidden image. The hidden image is positioned off-screen to the left, while there is a table of images in the center of th ...

Determining the Size and Color of Squares in a Treemap Based on Content with D3.js

I encountered an issue with a treemap visualization. I came across an example that is similar to my situation, which can be viewed here: In the demo, you can see that the size of each square in the treemap is determined by the content size. However, all s ...

Utilizing Java to extract dynamically generated content from an HTML page

I have an HTML page that looks like this: <html> <head> <!-- necessary java scripts --> </head> <body> <div id="content"></div> </body> After the page renders, a lot of dynamic html content is placed within ...

Encountering memory leaks and displaying repetitive data due to having two distinct observables connected to the same Firestore

I am currently utilizing @angular/fire to retrieve data from firestore. I have two components - one serving as the parent and the other as the child. Both of these components are subscribing to different observables using async pipes, although they are bas ...

How can you call a function in ExpressJS that is located in a different file?

I am having trouble with my UserController and database configuration file db.js. I am trying to make a function in the UserController access a function in db.js. In my UserController, I have included var db = require('../config/db'); and within ...

How can we integrate fixed-data-table-2 sorting with an existing redux store?

Any help or advice you can offer would be greatly appreciated. I am still fairly new to using react. I recently took on a project for a client that was already in progress, and everything has been going smoothly up until now. I've come across a stumb ...