What is the best way to incorporate CSS animations into JavaScript for mobile devices?

I need a way to copy text to the clipboard and show an alert confirming that it was copied successfully.

When the user clicks/touches the coupon PRIMEIRACOMPRA, the text "cupom copiado" changes its opacity to 1 and runs an animation to hide it.

See Example

UPDATE: After fixing a cache issue, I noticed that the animation doesn't work a second time. It should reset the opacity to 1 on every button click, but it's not happening. What could be causing this?

Here is the script I'm using:

function copyCupom() {
  var copyText = document.querySelector(".offer-right__coupon input");
  copyText.select();
  copyText.setSelectionRange(0, 99999); // For mobile devices
  navigator.clipboard.writeText(copyText.value);
  var textwascopied = document.querySelector(".offer-right__main .alert-coupon");
  textwascopied.style.opacity = "1";
  textwascopied.style.webkitAnimation = "hideText 1s ease-in 2s";
}

And the corresponding CSS:

.offer-right__main .alert-coupon {
    opacity: 0;
    animation-fill-mode: forwards !important;
    transition: 1s all;
}

@-webkit-keyframes hideText {
  to {
    opacity: 0;
  }
}

The function is triggered by clicking on the coupon button, and it works well on desktop but not on mobile!

<button onclick="copyCupom()">

What am I missing here?

The message "Cupom copiado" indicating that the text was copied does not disappear on mobile devices. I tried adding a webkit animation with no luck.

textwascopied.style.webkitAnimation = "webkit-hideText 1s ease-in 2s";
textwascopied.style.animation = "hideText 1s ease-in 2s";

@-webkit-keyframes webkit-hideText {
  to {
    opacity: 0;
  }
}

@keyframes hideText {
  to {
    opacity: 0;
  }
}

Answer №1

Why not give setting the v-bind:class attribute a try? You could use

v-bind:class="your-class"
, and then make any necessary modifications with CSS.

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

Extracting the value from a Text Editor in React Js: [Code snippet provided]

Currently, I am in the process of developing a basic app that generates a JSON form. So far, I have successfully incorporated sections for basic details and employment information. The basic details section consists of two input fields: First Name and Las ...

How can you disable the onClick function in React when the web browser width is smaller than the specified limit?

When using a mobile device, my onClick function serves two purposes: opening/closing the menu and changing the status of my Hamburger menu. However, both functionalities are active even when the navigation is set up for desktop screens. I want to disable t ...

Encountering an error while trying to install with npm: getting an error message that says "Cannot read property '

Encountering a puzzling error during the installation process with `npm install`, even though it functions properly on other devices. NPM and Node versions: C:\Users\Work>npm -v 8.3.2 C:\Users\Work>node -v v14.16.1 Presenting t ...

Tips for maintaining the default arrow icon for HTML select elements

While styling a drop down in Firefox on Mac OS X, I noticed that the arrow changes from the standard look to an unattractive downward arrow. How can I maintain the standard form element with the appealing up and down arrows, instead of the unsightly downwa ...

Trouble with X-editable linking to database for updates

Utilizing the X-Editable plugin within my PHP application to update fields in a table and utilizing a POST file to update the database. Below is the form code: <table id="restaurant" class="table table-bordered table-striped"> <tbody> ...

What are the benefits of incorporating a mock AJAX call in testing scenarios?

I recently came across a tutorial on TDD React here and I'm having trouble understanding the following test scenario: it('Correctly updates the state after AJAX call in `componentDidMount` was made', (done) => { nock('https://api. ...

Guide on creating Jasmine tests for $resource in AngularJS

Trying to get started with defining tests for my angular app, but feeling a bit lost as it's my first time working with testing. I'm specifically interested in setting up Tests with Jasmine for REST Services within my application. My main questi ...

Implementing Angular $resource to prepopulate a form with data

My goal is to enable CRUD operations so that when a user selects a specific item to edit, the form will automatically populate with the corresponding values for editing. Below is an excerpt of code from the 'storeView.html' file: <tr data-ng ...

exploring XML documents

With around 250,000 XML files, each named with a UUID, I am looking for the most effective way to perform a full text search on these files and identify the UUID of the matching ones. What would be the optimal approach for indexing them in a nodejs environ ...

How can I generate a hyperlink for a specific directory on Github Pages?

If I have a repository with one file and one folder, as listed below: index.html folder The folder contains another file named: work.html My goal is to access the folder website using only the link: username.github.io/repositoryname/folder Instead ...

What are some ways to calculate the average of data values in a Vue v-simple-table?

I am working with a v-simple-table. The "TotalAverage" value represents the total average of "ggFinalgrade". How can I retrieve this value? View current image The image I want to display The initial value is 20 calculated as (30+20+10)/3=20 The seco ...

Looking to verify a disabled select element and adjust the opacity of that element when it is disabled

$_product = $this->getProduct(); $_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); ?> <?php if ($_product->isSaleable() && count($_attributes)):?> <dl> <?php foreach($_attrib ...

Adjust the size of points positioned absolutely on an image map

Are you struggling to position POIs on a picture map correctly? Check out this link for more information: Even after trying CSS scale and re-positioning in media queries, getting the points in the right place seems impossible. What do you think? Can this ...

Tips for aligning an image in the center with a background attachment

I am facing an issue where only half of the image shows up when inserting the fixed effect. I need the entire image to be visible on the right side while adapting it for mobile devices. * { margin: 0; padding: 0; box-sizing: border-box; } .con ...

Guide on displaying the appropriate component in NextJs routes

Whenever I switch routes, I encounter an issue. While navigating between pages works fine, dynamic routes are not rendered correctly. In the routes, I have a folder called uw with a file named [table].js inside. For example, when I manually navigate to uw ...

Lack of consideration for height within tables positioned absolutely

In the case of an absolutely positioned element with display: table, if the height is explicitly set and the content exceeds this height, the element will adjust to wrap around the content rather than maintaining the specified height value. #main { wi ...

Switch up the box-shadow color with ColorThief!

Is there a way to adjust this script to change the box-shadow color of #player1? <script type="text/javascript> $(window).ready(function(){ var sourceImage = document.getElementById("art"); var colorThief = new ColorThief(); var color = ...

Accessing PageController through XmlHttpRequest is not allowed in Shopware 6

I'm encountering an issue when attempting to send a request to my customized StorefrontController on the most recent version of Shopware 6.2.2. The error message I'm receiving is: PageController can't be requested via XmlHttpRequest. I&apos ...

Which javascript library provides the top-notch SVG graphics support for Internet Explorer and other web browsers?

Currently, I am developing a web application using javascript and jquery that involves drawing numerous rectangles and lines connecting them. It seems like I need to find an SVG graphics library to create lightweight components (approximately 300). The ch ...

What are the steps to incorporate @svgr/webpack into turbopack within a next.js project?

I'm encountering an issue with turbopack and @svgr/webpack in my project. According to the documentation, they should work together but it's not cooperating. When I run the project without using --turbo (turbopack), everything functions as expec ...