Executing functions after the completion of a CSS animation

I am currently utilizing Vue3. I have implemented a feature where the box grows in size when the mouse hovers over it.

.curl:hover {
 width: 200px;
 height: 200px;
}

I am looking for a way to notify the user once the animation is complete and the size has been adjusted.

In simpler terms, similar to the animate() function in jQuery, I am seeking a method to execute a function upon completion of the animation without relying on jQuery. Does CSS or Vue offer a built-in solution for this?

Answer №1

After conducting research, I found a helpful tutorial that addresses your question.

Essentially, to achieve the desired outcome, you must specify a JavaScript handler type, animationend, by utilizing an eventhandler add function. This function requires the method you want to execute as the second argument, while also indicating the element undergoing animation as the target for the event.

Key components have been annotated within the code

//Obtain reference to the animated element
const animated = document.getElementById("divBoii");

//Include animation event listener along with associated function
animated.addEventListener('animationend', () => {
  console.log('Animation ended');
  document.getElementById("alert").innerHTML=":)";
});
<head>
  <style>
  /*Animation assigned to animated div */
  @keyframes animation{
    0%{
      padding:5%;
      height:auto;
    }
    100%{
      padding:10%;
      height:auto;
    }
  }
  body{
    width:100%;
    height:100%;
    background-color:teal;
  }
  #divBoii{
    margin:40%;
    margin-top:10%;
    width:10%;
    padding:5%;
    background-color:green;
  }
  /*Assign animation to div*/
  #divBoii:hover {
    animation-name:animation;
    animation-duration:3s;
  }
  
  </style>
  <body><div id="alert">
        This will be a smiley face when animation ends
      </div>
      <div id="divBoii">
      Here is some content we are going to animate
      </div>
  
  </body>
</head>

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

Learn how to create a dynamic React.useState function that allows for an unlimited number of input types sourced from a content management system

Currently, I am exploring the possibility of dynamically creating checkbox fields in a form using DatoCMS and the repeater module. My idea is to generate multiple checkbox fields based on the input from a text field in Dato as a repeater, which can then be ...

Having trouble retrieving input field values with Angular.js

I am struggling to access the input field values in my Angular.js application. Below is the code snippet I am using: <div class="input-group bmargindiv1 col-md-12"> <span class="input-group-addon ndrftextwidth text-right" style="width:180px"& ...

Is it possible for one AngularJS application to influence another?

In my latest AngularJS project, I developed an application for user creation. Depending on the selected user type, specific input fields are displayed. Upon submission, the data is sent to the server in JSON format. So far, everything is working smoothly. ...

Attempting to trigger an action from a Vuex module proves futile as the error message "[vuex] unknown action type" is generated

I've been struggling to successfully register a Vuex module. Below is the code I've been working with: stores/index.js: import Vuex from 'vuex'; import resourcesModule from './resources'; import axios from '@/helpers/ax ...

The xmlhttp object parameter is not defined. JavaScript AJAX

As a newcomer to javascript and ajax, I am trying my best to understand it all. I followed a tutorial to write this code, but I can't seem to figure out what I did wrong. If you click here, you can see the live version. The error message that Firebug ...

Utilize the scope for promise .then() functions when calling a service

I've just started using AngularJS and I have a question about handling promises in controllers. In my controller, I'm calling a service that communicates with a webservice and returns a promise. I want to apply the data from the promise's s ...

Is it possible to change sidebars in a spreadsheet if you are not a member of Google Workplace?

I am currently working on developing a Google Spreadsheet Add-on using GAS. I intend to switch between sidebars by utilizing the HtmlService class method. Here is the code snippet that I have implemented: function showSidebarA() { const ui = HtmlService ...

How to Align <ul> to the Right in Bootstrap 4

Looking to align a list to the right in the header section, here is the code snippet: <div class="collapse navbar-collapse" id="app-header-nav"> <ul class="navbar-nav mr-auto mt-2 mt-lg-0"> <li class="nav-item"> <a class=" ...

Authentication Error (401) in WordPress JWT

Recently, I came across WordPress and started using it. However, I encountered some issues while trying to integrate JWT with a custom endpoint. Despite configuring my API and JWT correctly, I faced an authentication problem during my AJAX request. It&ap ...

Extension for Chrome browser

I am new to creating Chrome extensions and I am attempting to build one that will display the IDs of all elements with a specific class name on a website in the popup window. I would like to know if there is a better way to tackle this issue. Thank you for ...

Align the subtext to the right and center it vertically within a Bootstrap dropdown menu item

Is there a way to vertically align small captions on the right side of a dropdown menu, next to each item's text? The issue is that in the example below, the numbers are not properly aligned. https://i.stack.imgur.com/NZigW.png The numbers 123 and 1 ...

I'm looking to locate the API documentation for AngularJS TypeScript

After transitioning from using AngularJS 1.4 and plain JavaScript to now working with AngularJS 1.5 but utilizing TypeScript, I have found it challenging to find helpful documentation. For instance, when trying to inject services like $q or $timeout into m ...

After making a POST request, I must ensure that the page is rendered accordingly

How can I efficiently handle requests to the server and update the page without reloading it, following SPA principles using useEffect()? I attempted to implement something like this: useEffect (() => { addProduct (); }) but it proved to be ineffectiv ...

Pressing ctrl+s will submit TinyMCE+JEditable

Updated: June 8th, 2011 Please check out the solution provided in the Answer section below. Updated: May 5th, 2011 I am currently facing a challenge where I need to trigger the JEditable submit button after hitting Ctrl+S. Thariama has already demonstr ...

Lost: pointer for speech bubble

Here is the HTML code I have written: <!DOCTYPE html> <html> <head> <style type="text/css"> #box { width: 200px; height: 250px; border-radius: 15px; background-color: pink; ...

dissecting mongo queries using nodes

I am thinking about organizing my mongo db queries into a separate js file to make it easier to reuse the code. I have tried the format below but it doesn't seem to work. Does anyone have any suggestions on how I could accomplish this? queries.js va ...

Eliminating the Scrollbar from Bootstrap 4 DataTable Causes Table Width to Decrease

My tables are causing a horizontal scroll bar to appear when converted to Bootstrap data tables. Adding the "p-3" class to the table's div for padding eliminates the scroll bar but also narrows the table. Is there a solution to removing the scroll b ...

Deploy a Next JS website within a subdirectory using traefik

I'm having trouble publishing a website in a subfolder (example.com/sitename) using Traefik. The website is built with Next JS. When I deploy, all script links in the built site ignore the folder (sitename). For example, a js script named generatedf ...

Error: The property 'rows' cannot be read because it is undefined

While working through the steps outlined in Getting started with Postgres in your React app, specifically when processing and exporting the getMerchants, createMerchant, and deleteMerchant functions, I encountered an error that says: "TypeError: Cannot rea ...

Tips for resolving undefined error handling in node.js

const fileSystem = require('fs'); const fileName = './prices.json'; const file = require(fileName); const price = require('./prices.json'); const fileName = './prices.json'; if(tmd = message.match(/^!change max ...