In the second tutorial in this series, you learned how to use KUTE.js to animate different CSS properties of elements on a web page. You learned how to animate all transform properties as well as properties such as border-radius
and border-color
. You can also use CSS plug-ins to animate CSS properties such as font-size
, line-height
, letter-spacing
, and Word Spacing
.
KUTE.js also has a text plugin that allows you to animate text within different elements by increasing or decreasing numbers like countdowns or writing strings character by character.
In this tutorial, you will learn how to animate text within different elements on a web page using CSS and text plugins in KUTE.js.
Animated CSS text properties
As I mentioned before, you can animate four different text-related CSS properties using the KUTE.js CSS plugin. These properties are font-size
, line-height
, letter-spacing
, and word-spacing
. We'll also animate individual letters using some properties of the core engine discussed in the first tutorial. Let’s see how all these concepts can be used together in the demo below to create a vibrating HELLO text.
Here is the code used to create the above animation:
var theLetters = document.querySelectorAll("span"); var h = document.querySelector(".h"); var e = document.querySelector(".e"); var la = document.querySelector(".la"); var lb = document.querySelector(".lb"); var o = document.querySelector(".o"); var startButton = document.querySelector(".start"); var animateColor = KUTE.allFromTo( theLetters, { color: 'white' }, { color: 'red' }, { offset: 200, duration: 50} ); var animateFontSize = KUTE.allFromTo( theLetters, { fontSize: '2em' }, { fontSize: '4em' }, { offset: 100, duration: 200, repeat: 10, yoyo: true} ); var animateSkewing = KUTE.allTo( theLetters, { skewX: -15}, { offset: 200, duration: 200 } ); var animateH = KUTE.to( h, { color: '#009688' } ); var animateE = KUTE.to( e, { translateY: -40, color: '#E91E63' } ); var animateLA = KUTE.to( la, { color: '#8BC34A' } ); var animateLB = KUTE.to( lb, { translateY: 20, color: '#FFC107' } ); var animateO = KUTE.to( o, { color: '#FF5722' } ); var lettersSqueezed = KUTE.allTo( theLetters, { letterSpacing: '-15px' }, { offset: 0, duration: 200 } ); animateColor.chain(animateFontSize); animateFontSize.chain(animateSkewing); animateSkewing.chain(animateH, animateE, animateLA, animateLB, animateO); animateE.chain(lettersSqueezed); startButton.addEventListener( "click", function() { animateColor.start(); }, false );Each letter of the
word is contained within the span
tag and has its own unique class. The first tween changes the color of all letters from white to red with an offset of 200 milliseconds. This is also the first animation played after clicking Start Animation. animateFontSize
The tween is linked to animateColor
. This way, once the color animation ends, the font-size
animation will start.
You may have noticed that I use two properties called repeat
and yoyo
to control the behavior of the animation. yoyo
Property is used to reverse the animation that is currently playing on repeat. This avoids sudden jumps in the values of different properties during animation, making it appear smooth.
font-size
animation is linked with animateSkewing
, which skews all letters -15 degrees. The skewX
and skewY
properties are available in the core engine itself.
All tweens used to animate the colors of different letters are now linked to animateSkewing
. This way you ensure that all linked color animations start playing after the tilt animation ends. Finally, the lettersSqueezed
tween reduces the spacing between different letters by 15 px.
You can create more interesting effects by using different combinations of properties.
Animated Numbers
You can also animate numbers in KUTE.js. However, you must include additional text plugins to create animations.
The process of digital animation is actually very simple. You just need to specify the selector at which the animation number should be displayed and the final number at which the animation should end.
This is a basic example using animation to show the total number of U.S. airports in 2016.
var usa = document.querySelector(".usa"); var startButton = document.querySelector(".start"); var animateUSA = KUTE.to( usa, { number: 19536 } ); startButton.addEventListener( "click", function() { animateUSA.start(); }, false );
You can also apply common tweening options such as duration
, repeat
, and delay
to customize the behavior of your animation. The code we just wrote will produce the following animation:
Write text character by character
This is a very popular effect and you can find it on many websites. The KUTE.js text plugin allows you to specify new sentences that replace the original sentences one character at a time.
The random characters are animated like the numeric example you just saw, before replacing the initial characters with the final values. The embedded CodePen demo should make it clearer:
Here is the code you need to write to create the above animation:
var animateHeading = KUTE.to( heading, { text: '70% Surface of Earth is Covered with Water.' }, { duration: 5000} ); startButton.addEventListener( "click", function() { animateHeading.start(); }, false );
整个句子的人物动画在5秒内完成。您可能已经注意到,首句和末句不需要具有相同数量的字符。这给我们在设置 text
参数的值时提供了很大的自由度。
您还可以在 text
参数的值中包含 HTML 标记,然后使用 CSS 更改刚刚设置动画的文本的外观。
var animateHeading = KUTE.to( heading, { text: '70% SURFACE OF <span class="earth">EARTH</span> IS COVERED WITH <span class="water">WATER</span>.' }, { duration: 10000, textChars: 'upper' } );
地球出现后,地球的出现将会延迟。发生这种情况是因为插件还使用相同的角色动画编写 <span class="earth"></span>
,但这些角色实际上对用户来说都不可见。根据您的喜好,延迟可能是理想的,也可能是不理想的。
动画期间显示的中间字符默认为小写字母值。当您想要设置动画的字符均为大写字母或数字时,这可能会成为问题。动画使用哪些中间字符由 textChars
参数的值决定。它接受六个不同的值:
-
alpha
:在这种情况下,中间字符将为小写字母。 -
upper
:在这种情况下,中间字符将为大写字母。 -
numeric
:在这种情况下,数字字符用于动画。这与对数字进行动画处理不同,因为值不会按顺序增加。 -
symbols
:在这种情况下,插件将使用 #、% 和 $ 等字符来表示动画。 -
all
:如果您希望中间字符是字母、数字和符号的混合,则可以使用此值。 - 如果没有其他方法适合您,KUTE.js 可以让您选择指定动画期间应使用的自定义字符列表。
以下示例演示如何使用大写中间字符为标题内的文本添加动画效果。
最终想法
在本教程中,您学习了如何使用 KUTE.js 中的 CSS 和文本插件来为元素内的文本添加动画效果。当你想要为文本的外观添加动画效果时,你需要使用 CSS 插件。这将允许您使用 font-size
、letter-spacing
等属性。当您想要更改任何元素内的实际字符时,您需要使用文本插件。
如果您正在寻找其他 JavaScript 资源来学习或在工作中使用,请查看我们在 Envato Market 上提供的资源。
我希望您在本教程中学到了一些新东西。如果您有任何疑问,请在评论中告诉我。
The above is the detailed content of Efficient text animation with KUTE.js: Part 4, Text animation. For more information, please follow other related articles on the PHP Chinese website!

Enable comments on your WordPress website to provide visitors with a platform to participate in discussions and share feedback. To do this, follow these steps: Enable Comments: In the dashboard, navigate to Settings > Discussions, and select the Allow Comments check box. Create a comment form: In the editor, click Add Block and search for the Comments block to add it to the content. Custom Comment Form: Customize comment blocks by setting titles, labels, placeholders, and button text. Save changes: Click Update to save the comment box and add it to the page or article.

How to copy WordPress subsites? Steps: Create a sub-site in the main site. Cloning the sub-site in the main site. Import the clone into the target location. Update the domain name (optional). Separate plugins and themes.

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.

Enable comments in WordPress website: 1. Log in to the admin panel, go to "Settings" - "Discussions", and check "Allow comments"; 2. Select a location to display comments; 3. Customize comments; 4. Manage comments, approve, reject or delete; 5. Use <?php comments_template(); ?> tags to display comments; 6. Enable nested comments; 7. Adjust comment shape; 8. Use plugins and verification codes to prevent spam comments; 9. Encourage users to use Gravatar avatar; 10. Create comments to refer to

You can install the FTP plug-in through WordPress, configure the FTP connection, and then upload the source code using the file manager. The steps include: installing the FTP plug-in, configuring the connection, browsing the upload location, uploading files, and checking that the upload is successful.

How to copy WordPress code? Copy from the admin interface: Log in to the WordPress website, navigate to the destination, select the code and press Ctrl C (Windows)/Command C (Mac) to copy the code. Copy from a file: Connect to the server using SSH or FTP, navigate to the theme or plug-in file, select the code and press Ctrl C (Windows)/Command C (Mac) to copy the code.

WordPress Error Resolution Guide: 500 Internal Server Error: Disable the plug-in or check the server error log. 404 Page not found: Check permalink and make sure the page link is correct. White Screen of Death: Increase the server PHP memory limit. Database connection error: Check the database server status and WordPress configuration. Other tips: enable debug mode, check error logs, and seek support. Prevent errors: regularly update WordPress, install only necessary plugins, regularly back up your website, and optimize website performance.

How to turn off a comment in WordPress? Specific article or page: Uncheck Allow comments under Discussion in the editor. Whole website: Uncheck "Allow comments" in "Settings" -> "Discussion". Using plug-ins: Install plug-ins such as Disable Comments to disable comments. Edit the topic file: Remove the comment form by editing the comments.php file. Custom code: Use the add_filter() function to disable comments.


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

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

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.