HTML, CSS and jQuery: Animating an Icon
HTML, CSS and jQuery: Making an Icon Animation Effect
In modern web design, icon animation effects have become a very popular and important element. By adding some movement and interaction, you can make your web page more lively and attract the user's attention. This article will introduce how to use HTML, CSS and jQuery to create a simple and cool icon animation effect.
First, we need to prepare some basic HTML code to build our icon animation effect.
<!DOCTYPE html> <html> <head> <title>图标动画效果</title> <link rel="stylesheet" type="text/css" href="style.css"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="script.js"></script> </head> <body> <div class="container"> <div class="icon"></div> </div> </body> </html>
In the above code, we introduced a style sheet file style.css
and a script file script.js
. Next, we will use these two Complete our icon animation effect in one file.
In the style.css
file, we will define the style of the icon and animation effects.
.container { width: 200px; height: 200px; position: relative; } .icon { width: 50px; height: 50px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #ff5a5a; border-radius: 50%; animation: bounce 2s infinite; } @keyframes bounce { 0% { transform: translate(-50%, -50%); } 25% { transform: translate(-50%, -150%); } 50% { transform: translate(-50%, -50%); } 75% { transform: translate(-50%, 50%); } 100% { transform: translate(-50%, -50%); } }
In the above code, the .container
class is a container used to contain our icon elements. The .icon
class is a round red icon that is turned into a circle using the border-radius
property. We also defined an animation named bounce
, which specifies the position of the element at different points in time to achieve a rebound effect. We applied this animation to the .icon
class and set a 2-second loop.
Next, we need to add some jQuery code to the script.js
file to achieve the interaction between the user and the icon.
$(document).ready(function() { $(".icon").click(function() { $(this).addClass("active"); setTimeout(function() { $(".icon").removeClass("active"); }, 2000); }); });
In the above code, we use the $(document).ready()
method to ensure that the page is fully loaded before executing the code. When the user clicks on the icon element, we will add a class to it called active
. At the same time, use the setTimeout()
method to remove the class after 2 seconds to achieve a post-click change effect.
Finally, we save the above codes to the corresponding files and place them in the same directory as the HTML files. Open the HTML file in your browser and you will see a red icon bouncing around in the container, and when you click on it, it will fade in and out, which is really cool.
To sum up, by combining HTML, CSS and jQuery, we can easily create an icon animation effect, add more dynamic and interactive effects to the web page, and improve the user experience. I hope this article is helpful to you, thank you for reading!
The above is the detailed content of HTML, CSS and jQuery: Animating an Icon. For more information, please follow other related articles on the PHP Chinese website!

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.
