This time I will bring you anime.js to make animationsCheck boxes, what are the precautions for making animated check boxes with anime.js, the following is a practical case , let’s take a look.
anime.js
anime.js is a flexible and lightweight JavaScript animation library.
It works with CSS, individual transforms, SVG, DOM properties and JS objects.
Features
Specific animation parameters
-
Specific target values
- ## Multiple timing values
- Playback Control
- Motion Path
<svg> <circle></circle> </svg>The above code is concise and clear. It mainly draws a green circle with a radius of 16px:
var checkTimeline = anime.timeline({ autoplay: true, direction: 'alternate', loop: true }); checkTimeline .add({ targets: '.checkmark', scale: [ { value: [0, 1], duration: 600, easing: 'easeOutQuad' } ] })Briefly explain this code. First, an instance of animation is defined, and through autoplay, direction and loop, the animation is defined to play automatically and to execute the animation in a loop. Use the targets parameter to specify the element to be animated, that is, the checkmark, which is scaled from 0 to 1. The animation time is 600 milliseconds, and the motion curve of the animation is also defined.
使用曲线在动画开发中是一个必不可少的一部分,它可以使动画的体验更加舒服自然。在实际开发中,为不同类型的动画选择不同的动画曲线也是做动画时,必须要注意的一点。曲线选择也受制于具体动画的场景,比如形状与形状之间的动画,抛物线运动等等,总而言之就是要复合物理运动的一个规律。在CSS3中经常使用的运动曲线是ease-in、ease-out和ease-in-out这三个,比如ease-out表示缓出动画,缓出使动画在开头处比线性动画更快,还会在结尾处减速。ease-out缓入动画,缓入动画开头慢结尾快,与缓出动画正好相反。一般在UI界面动画中,适合使用缓出动画即ease-out。所以,在这个复选框的动画实例中,适合使用缓出动画。
接下来是勾的动画。像勾这类的形状通常由SVG中的路径(path)来实现。具体路径的详细介绍,可以去这篇文章看看。在实际开发中,一般都是使用诸如AI或者是Inkscape等矢量设计工具来设计,然后导出SVG格式。具体到这个勾,实现起来也非常简单,三个锚点就可以实现一个勾的形状。最后设置linecap的属性的值为2.5px来实现勾的两端的圆角效果。
这里要注意的一点的是:要在整个设计过程中,遵守一定的设计原则。比如在这个效果中,一致性就是一个重要的设计原则。如果在静态的图形中,使用了圆角,那么在动画中最好也要保持这个圆角。当然你也可以使用方的角。总之,在整个过程中,请保持UI的一致性。
导出来代码如下:
<path></path>
和圆整合一下,效果如下:
现在看起来还不错,只剩下最后一步就是这个勾要做一个绘制的动画效果。使用SVG实现描边动画效果讲了很多了。在anime.js中,实现一个描边绘制动画也非常简单,它提供了anime.setDashoffset这个方法来计算路径(path)的长度,使用它就可以实现一个绘制的动画效果。代码如下:
checkTimeline .add({ ... }) /* Previous steps */ .add({ targets: '.check', strokeDashoffset: { value: [anime.setDashoffset, 0], duration: 700, delay: 200, easing: 'easeOutQuart' }
还是老套路,先选择要做动画的元素。后面是来设置路径(path)的dashoffset的值,初始的值整个路径(path)的长度,整个路径是在画布外的不可见;通过anime.setDashoffset方法,把它的值设置为0,出现在画布中,就可以实现绘制动画效果。
最后还通过设置勾的transform来移动它的位置,使它居于圆圈的中心位置。
OK,一个带有动画效果的复选框就完成了!可以发现使用anime.js来开发动画效果还是很简单的。
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
The above is the detailed content of anime.js makes animated checkbox. For more information, please follow other related articles on the PHP Chinese website!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


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

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

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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