In Safari, an animated link does not respond to pointer-events, making it unclickable

Exploring the world of CSS animations, I have created a snippet where elements appear sequentially. Take a look at it first:

.wrapper {
  pointer-events: none; /* disable pointer events until animation completes */
}

.text {
  position: absolute;
}

/* First element starts visible and fades out after 2s */
.first {
  opacity: 1;
  animation: fade 500ms reverse forwards 2000ms;
}

/* Second element starts hidden and fades in after 3s */
.second {
  opacity: 0;
  animation: fade 500ms forwards 3000ms;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
    pointer-events: all; /* re-enable pointer events after animation */
  }
}
<div class="wrapper">
  <h1 class="text first">Wait 2 seconds...</h1>
  <h1 class="text second">Now <a href="https://example.com">click</a></h1>
<div>

In this code snippet, you'll notice that the second element contains a link. By default, the link remains clickable throughout the animation, even when it's not visible due to opacity being set to 0.

To address this, I've implemented a workaround by setting pointer-events: none; on the parent element and then switching it to pointer-events: all; on the children once the animation is complete (inside @keyframes).

While this technique works flawlessly in Chrome and Firefox, it seems to encounter an issue in Safari. Despite setting pointer-events: all;, the link doesn't become clickable at the end of the animation, potentially indicating a bug specific to Safari.

(You can replicate the problem or explore alternative solutions in this CodeSandbox)

Here are some questions that arose as I encountered this issue:

  • Could this be a bug inherent to Safari? While browsing through Webkit's issue tracker, no pertinent information was found (despite numerous other pointer-events related bugs).
  • Is there a way to resolve this Safari-specific behavior without resorting to JavaScript?

I appreciate any insights you may have!

Edit

After further investigation, I came across a potential solution for Safari involving the use of visibility: hidden; instead of manipulating pointer-events, which is detailed below.

Additionally, upon testing my code with Playwright (an automated testing tool capable of launching a headless WebKit browser), the pointer-events bug did not manifest. This raises the question of whether the issue is exclusive to Safari rather than being a broader WebKit concern. Further clarification on this matter would be greatly appreciated!

Answer №1

After much consideration, I have devised a solution that is also compatible with Safari:

.text {
  position: absolute;
}

/* The initial element is visible and gradually fades out after 2 seconds */
.first {
  opacity: 1;
  visibility: visible;
  animation: fade 500ms reverse forwards 2000ms;
}

/* The second element is initially hidden and smoothly fades in after 3 seconds */
.second {
  opacity: 0;
  visibility: hidden;
  animation: fade 500ms forwards 3000ms;
}

@keyframes fade {
  from {
    opacity: 0; /* Opacity is needed for the animation */
    visibility: hidden;
  }
  to {
    opacity: 1;
    visibility: visible;
  }
}
<div>
  <h1 class="text first">Wait for 2 seconds...</h1>
  <h1 class="text second">Now, <a href="https://example.com">click here</a></h1>
<div>

Rather than disabling pointer-events, I propose using visibility: hidden; to prevent the link from being clickable prematurely.

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

the content outside of the division is incorrectly formatted

Here is the code snippet that I am working with: <html lang='es'> <head> <link rel="stylesheet" type="text/css" href="theme.css"> <link rel="stylesheet" type="text/css" href="bootstrap337/css/bootstrap.mi ...

BEM Methodology: Ensuring the CSS value in one block takes precedence over property definitions in another block

I'm facing a challenge with BEM as I try to make properties from one block take precedence over styles in another. Some might suggest adding a modifier for .button, but in some cases, specific properties need to be applied only on certain pages withou ...

My HTML and CSS design is not displaying correctly on mobile devices

Currently, I am in the process of utilizing a free website template. However, I am facing an issue with adjusting the background image. Is there anyone who can provide some guidance on resolving this particular problem? I would be happy to share the code ...

Displaying a variable in a live HTML user interface

I have successfully created a Python program that captures data from an Arduino Potentiometer and shows it on the Python console. Now, I am working on enhancing the output by displaying it in a local HTML file. I am seeking guidance on how to incorporate t ...

The code "transform: rotate(' ')" does not seem to be functioning properly in Javascript

I set out to create a simple spin wheel exercise, but it quickly became more challenging than I anticipated. After researching how to make one online, I found code similar to mine that worked on a JSFiddle Example, yet my own code still didn't work. ...

Tips for referencing the second class when two classes share the same name in Selenium WebDriver

I am trying to retrieve the text from the second "109-top-dark-grey-block ng-binding" class, which is currently null but will contain some text in the future. I have attempted using tabIndex and nth-child selectors, but neither have been successful. " < ...

Navigating on the horizontal axis within a container with overflow properties

I am trying to insert multiple children-divs into a parent-div. The parent div has a fixed width. The children are set to float left and will overflow the container. I need the ability to scroll along the x-axis. However, when I attempt to do this, the c ...

Implementing a loop with jQuery in a React application

I encountered an error stating that the i is not defined, even though I have already initialized the npm install jQuery and imported it. Here is a screenshot of the error: https://i.sstatic.net/SV8Ww.png This is my code snippet: isClick ...

What is the best way to apply CSS to a mat-row element only when it is being hovered over?

I have a table with rows where a specific condition triggers a light red background color for each row. On hover, the background changes to light gray for all rows. However, I need the special rows (already colored light red) to have a deeper shade of red ...

Implementing smooth transitions on iPad screens with responsive text

I am currently working on a personal project that involves creating images with hover transitions. The transition effect works perfectly on all browsers except for iPads. I'm facing an issue where I can't click on the image due to the presence of ...

Utilizing the Bootstrap grid system for responsiveness is optimized for a first word that is precisely 15 characters

Trying to achieve responsiveness using basic Bootstrap. The layout becomes responsive only when the initial word in a sentence contains more than 15 characters, as illustrated below. https://i.stack.imgur.com/wyErA.png <!-- Headers --> <div clas ...

The JavaScript-generated form element will not be included in the data submitted through the POST method

While it may appear that this question has been asked before, my specific inquiry seems to be unique as I have not found a similar answer in other threads. Therefore, I am initiating a new discussion. My issue revolves around a form which contains a link ...

When CSS width:auto expands beyond its intended length

I'm experiencing an issue when I set the width to auto, the div expands to full length rather than adjusting to the width of the inner divs. Here is the HTML code: <div class="vidswraper"> <div> <div class="videoimage"> <img src ...

I'm attempting to store this HTML code in local storage in order to utilize it on a new cart page, but I keep encountering an error

Here is the HTML snippet: <div class="cofefe"> <img src="photos/Shop%20-%20French%2Roast.png"> <p>Somecoffee</p> <p>15</p> <p>French ...

Challenges in aligning images side by side within an XSLT document

My XML file is currently being transformed using XSLT to display tables, but I would like these tables to be displayed next to each other in rows of three columns. However, the current output shows them displaying one after another vertically. Here's ...

What is the best way to limit the length of text in a div if it surpasses a

As I work on a website, users have the ability to add headings to different sections of a page. For example: M11-001 - loss of container and goods from Manchester Some headings can be quite detailed, but in reality, only the first few words are needed to ...

Setting up Angular Toolkit via npm installation

After successfully installing the UIKit npm package within an Angular 2 CLI project, what steps should I take to utilize it? I have also installed typings for UIKit (@types/uikit), but I am unsure of how to properly import the package into a controller i ...

Customizing the Dropdown Arrow Icon to a Desired Icon of Choice

I'm looking to customize the dropdown select on my website by changing the arrow icon to a plus icon, which will then turn into a minus icon when clicked and the choices are displayed. I'm new to jquery and eager to learn more about this language ...

Change the text of a button by using an input field

How can I dynamically update button text based on input field value? <input class="paymentinput w-input" type="tel" placeholder="0" id="amount-field"> <button id="rzp-button1" class="paynowbutton w-button">Pay Now</button> I want the bu ...

What is the method to extract div text using Python and Selenium?

Is there a way to extract the text "950" from a div that does not have an ID or Class using Python Selenium? <div class="player-hover-box" style="display: none;"> <div class="ps-price-hover"> <div> ...