CSS3动画代码相对简单,在性能上会比JavaScript动画稍微好一些,浏览器会对CSS3动画做一些优化(比如专门新建一个图层用来跑动画)。但CSS3动画对动画控制上不够灵活的缺点也很明显。如何像控制视频播放一样控制CSS3动画播放、暂停、重放呢?下面实例是我本人的一个尝试。
先点击此处查看效果。
CSS3的动画中,动画元素的animation-play-state属性规定动画是否正在运行或暂停。属性值为paused可指定暂停动画,属性值为running可指定正在运行的动画。默认是 “running”。因此使用JavaScript动态改变这两个值就可以控制CSS3动画播放、暂停了。
控制CSS3动画重放相对麻烦一点,主要的思路将动画元素的动画样式先删除再添加,要注意将动画样式独立成一个类选择器,这样方便直接利用classList对象的方法进行删除添加操作。另外,删除添加是两个操作之间要有时间间隔,用setTimeout就可以实现了。
即使借助JavaScript,对CSS3动画的控制也是有限的。复杂些的效果还得使用JavaScript动画。

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
