How to Re-trigger a WebKit CSS Animation via JavaScript
This question addresses the issue of re-triggering a CSS animation using JavaScript. The existing animation rule "@-webkit-keyframes shake" defines a shaking effect, but subsequent attempts to activate it again via JavaScript prove unsuccessful.
The solution provided leverages the "animationEnd" event, specifically "webkitAnimationEnd" for WebKit browsers. When this event is triggered, it indicates the completion of the animation.
To re-trigger the animation, an event listener is added to the element for the "webkitAnimationEnd" event. Upon receiving this event, the element's "webkitAnimationName" style property is cleared, effectively resetting the animation.
Example (Plain Vanilla JavaScript):
var element = document.getElementById('box'); element.addEventListener('webkitAnimationEnd', function(){ this.style.webkitAnimationName = ''; }, false); document.getElementById('button').onclick = function(){ element.style.webkitAnimationName = 'shake'; // You may want to prevent default action here. };
Example (jQuery):
var $element = $('#box').bind('webkitAnimationEnd', function(){ this.style.webkitAnimationName = ''; }); $('#button').click(function(){ $element.css('webkitAnimationName', 'shake'); // You may want to prevent default action here. });
Cross-Browser Support:
For cross-browser support, the "css3AnimationSupport" object can be used to detect CSS transition, transform, and animation properties supported by different browsers.
var css3AnimationSupport = (function(){ var div = document.createElement('div'), divStyle = div.style; return { transition: (function(){ return divStyle.MozTransition === ''? {name: 'MozTransition' , end: 'transitionend'} : (divStyle.MsTransition === ''? {name: 'MsTransition' , end: 'msTransitionend'} : (divStyle.WebkitTransition === ''? {name: 'WebkitTransition', end: 'webkitTransitionEnd'} : (divStyle.OTransition === ''? {name: 'OTransition' , end: 'oTransitionEnd'} : (divStyle.transition === ''? {name: 'transition' , end: 'transitionend'} : false)))); })() // ... Other detections omitted for brevity }; }());
The above is the detailed content of How to Restart a WebKit CSS Animation Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust

Using scroll shadows, especially for mobile devices, is a subtle bit of UX that Chris has covered before. Geoff covered a newer approach that uses the animation-timeline property. Here’s yet another way.

Let’s run through a quick refresher. Image maps date all the way back to HTML 3.2, where, first, server-side maps and then client-side maps defined clickable regions over an image using map and area elements.

The State of Devs survey is now open to participation, and unlike previous surveys it covers everything except code: career, workplace, but also health, hobbies, and more.

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools
