The CSS ::after selector is experiencing a decrease in animation speed

There is a dropdown menu set to fade in once a link is clicked. Everything works well, the menu fades in properly. However, when clicking off and triggering a function that fades out the dropdown, the triangle on top of the box fades out slightly slower than the actual box. The triangle is created using the :after selector in CSS.

Below is the HTML code:

<a href="#" class="Header-Link Right Account-Actions"><?php echo 'Welcome ' . $user->data()->fname . '!'; ?></a>
        <div class="Account-Links">
            <a href="#" class="Account-Link">My Account</a>
            <a href="logout.php" class="Account-Link">Sign Out</a>
            <a href="#" class="Account-Link">Help</a>
        </div>

CSS:

.Account-Actions {
    postition: relative;
}

.Account-Links {
    position: absolute;
    top: 45px;
    left: 0;
    display: block;
    visibility: hidden;
    margin: 0;
    padding: 0;
    width: 200px;
    height: 0;
    opacity: 0;
    box-sizing: border-box;
    background-color: rgba(0,0,0,.7);
    z-index: 1000;
    transition: all .2s ease-in-out;
    -moz-transition: all .2s ease-in-out;
    -webkit-transition: all .2s ease-in-out;
    -o-transition: all .2s ease-in-out;
}

.Account-Links-On {
    height: auto;
    visibility: visible;
    opacity: 1;
}

.Account-Links::after {
    position: absolute;
    top: -8px;
    right: 22px;
    content: '';
    width: 0;
    height: 0;
    border-bottom: solid 8px rgba(0,0,0,.7);
    border-left: solid 8px transparent;
    border-right: solid 8px transparent;
}

.Account-Link {
    display: block;
    color: #FFF;
    margin: 0;
    padding: 10px;
}

.Account-Link:hover {
    background-color: rgba(231,76,60,.75);
}

a {
    text-decoration: none;
}

a.Header-Link {
    position: relative;
    display: block;
    margin: 0 10px;
    padding: 0 8px;
    line-height: 47px;
    color: #777;
    border-bottom: 3px solid transparent;
}

a.Header-Link:hover {
    color: #000;
}

Javascript:

$(document).ready(function(){
        $('.Account-Actions').bind('click', function(){
            $('.Account-Links').toggleClass('Account-Links-On');
        });

        $('html').click(function() {
            $('.Account-Links').removeClass('Account-Links-On');
        });

        $('.Account-Links, .Account-Actions').click(function(event){
            event.stopPropagation();
        });
    });

Answer №1

By placing your arrow in a different class and toggling the opacity on another class, you can avoid the delay that occurs with .Account-Links. Instead, consider placing it in .Account-Links-On.

CHECK OUT THE DEMO

.Account-Links-On::after {
  position: absolute;
  top: -8px;
  right: 22px;
  content: '';
  width: 0;
  height: 0;
  border-bottom: solid 8px rgba(0,0,0,.7);
  border-left: solid 8px transparent;
  border-right: solid 8px transparent;
}

This clarifies that the :after pseudo selector does not animate more slowly.

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

Using React with Typescript: What is the best way to implement useMemo for managing a checkbox value?

I am currently developing a to-do list project using React and Typescript. At the moment, I have successfully implemented the functionality to add new to-do items via a form and delete them individually. Each item includes a checkbox with a boolean value. ...

Goodbye.js reliance on lodash

In my search for the most lightweight and speedy jQuery implementation for server-side NodeJs, I've come across Cheerio as the best option. However, I've noticed that Cheerio has a code-size of around 2.6 MB, with approximately 1.4 MB attributed ...

Navigate to the previous or next page using JavaScript

I've been struggling to figure out how to navigate one page up and down using simple links, but I haven't found a solution that works for me. The URL I am working with is: . When the "next page" button is clicked, it should go to ?page=2, and whe ...

Is there a more efficient alternative to `[].push.apply(this, arr)` for combining elements in an array instance within a constructor?

It only takes 0.15ms for this line in my constructor function to execute. [].push.apply(this, selector); I'm not satisfied with the 0.15ms execution time. I believe there must be a quicker alternative available. This particular line seems to be conv ...

Using jQuery to toggle the visibility of select options for multiple elements

Hey there, I've got this code snippet that effectively shows and hides elements based on a selected option. It works well with one element, but when I try to use it with multiple elements, it doesn't function correctly. How can I tweak it so that ...

Changing a p element to a div and adding a class in Bootstrap 4.5

To maintain consistency, I prefer using <div class='something'>BIO</div> over <p>BIO</p>. In Bootstrap 4.5, is there a similar class that achieves the same result? I'm not very skilled in CSS, so please forgive me i ...

First experience with Django Bootstrap Modal Ajax was flawless, but on the second attempt, it was not as successful

I am currently utilizing Django 2.2 in conjunction with Bootstrap. The method implemented is as follows: Triggering the opening of a modal window, User updates the data, User saves the data, Underlying table from where the window originated is updated a ...

What is the best way to vertically center a button against a video using CSS?

How can I vertically center a button against a video using CSS? Here is my code: https://jsbin.com/curefoyefe/edit?html,css,js,output <video controls="" ng-show="myForm_live_video.live_video.$valid" ngf-src="live_video" width="200" height="200" class= ...

What is the best way to ensure the correct display of my custom post type using Wordpress, isotope.js, and Bootstrap filtering?

I am encountering some difficulties when trying to display my custom post type based on category using isotope. It seems like it's almost there but I can't figure out why it's showing up strangely. There should be three Bootstrap columns in ...

Displaying information from an array in a view and manipulating it using JavaScript

Having trouble displaying array data in a customized way. Here is how my array structure looks: array:2 [▼ "folder1" => array:5 [▼ 0 => "4.png" 1 => "2.png" 2 => "1.png" 3 => "3.png" 4 => "5.png" ] "folder2" ...

Vue3 - Utilizing a method to dynamically alter an input property

Currently, I am in the process of developing a Vue application that incorporates a map feature. The main functionality involves determining whether a given position on the map is over water or land. If the position is over water, I want to iterate through ...

Executing Ajax invokes a PHP script which inserts data into MySQL database; interested in viewing any PHP error messages

Utilizing jquery, I am making an Ajax call to execute a php script for inserting data into a MySQL database. Everything functions smoothly on php7. However, while testing the code on php8, I encounter an error within the error function. An error seems to ...

Mobile devices not showing the Navbar bootstrap menu

My header.php works perfectly on desktop, but the navigation bar is not displaying properly on mobile devices. Here is my code: <!DOCTYPE html> <html> <head> <title>International Pvt. Ltd.</title> <meta name="viewpo ...

The Javascript Node class encountered an error: X has not been defined

I have a class that looks like this: const MongoClient = require("mongodb").MongoClient; const ConnectionDetails = require("./ConnectionDetails").ConnectionDetails; const Recipe = require("./recipe").Recipe; var ObjectId = req ...

Regular expressions: Capturing characters that come after and before a designated symbol

Is there a way to extract all letters, both before and after an underline "_", in JavaScript using Regex while excluding specific words like "pi", "\Delta" and "\Sigma"? How can this be achieved in Regex JS? /\b([^e|_|\d|\W])&bso ...

What is the best method for flipping the sequence of elements in media queries?

I am facing an issue with two divs, left and right, on my webpage. When the screen size is less than 500px, I want the left div to move to the bottom and the right div to move to the top. Essentially, I need to swap the positions of these divs in the DOM. ...

Whenever the ajax oncomplete event is triggered, Primefaces overrides the functionality of jquery, leading to

I have implemented a plugin for fixed table columns in my Primefaces project. The plugin is somewhat functional, but I am facing some issues. primefaces v6.1 jQuery v1.7.1 It works under the following conditions; p:dataTable with <p:ajax event="page ...

Utilizing HTML documents instead of images in Owl Carousel 2

I am currently utilizing owl carousel 2 to construct a basic sliding carousel. However, I am only using images at the moment and would like to incorporate HTML files instead. These HTML files contain multiple divs where images can be inserted, and instead ...

"Optimizing Long Polling for Maximum Efficiency: Tips for utilizing php, Jquery

Hey everyone, I'm looking to implement real-time flash message notifications for users when they receive a new private message in their inbox. What is the most effective way to achieve this using technologies like PHP 5.3, jQuery, and JSON? I prefer ...

Progressively modifying related elements over time intervals

I have a specific list of p elements in my HTML code that I need to modify sequentially with a time interval of 1 second. Here is the HTML: <p>Changing first sentence!</p> <p>Second sentence ready!</p> <p>Third one coming up ...