Saturday, May 17, 2025
News PouroverAI
Visit PourOver.AI
No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
News PouroverAI
No Result
View All Result

Building a 3D Card Flip Animation with CSS Houdini — SitePoint

February 14, 2024
in Cloud & Programming
Reading Time: 4 mins read
0 0
A A
0
Share on FacebookShare on Twitter



In this article, we will explore the features of Houdini by creating a 3D card flip animation. This will help you understand the core concepts of Houdini and guide you through implementing practical code. By using CSS Houdini, you can enhance your development workflow and create cutting-edge CSS animations, giving you more control over the animation process. Traditional CSS animations have limitations, but Houdini, with its collection of experimental browser APIs, breaks these limitations and allows developers to create custom visual experiences that were previously unimaginable, pushing the boundaries of web design.

Table of Contents
Key Concepts Covered in this Article

Here’s a breakdown of the key concepts covered in this article:

How to Work with Houdini’s Major Triad
CSS Houdini is a collection of browser APIs that empower developers to extend and enhance the capabilities of the browser’s rendering engine. With Houdini, developers can create custom animations, effects, and styles, pushing the boundaries of web design. In the upcoming sections, we’ll delve into a detailed explanation of the three primary APIs, unlocking their potential and understanding how they can elevate your web design and development capabilities.

Note: to enable Houdini on your browser, enter chrome://flags/ in the address bar, then search for experiments and activate it.

Worklets
Houdini worklets are JavaScript modules that operate within the browser’s rendering engine, allowing developers to define custom paint, layout, and animation behaviors, thereby extending the capabilities of CSS. With worklets, you can do the following:

Create dynamic animations.
Imagine animating the stroke width of a path based on user interaction or dynamically controlling the speed of an animation based on scroll position. These are some of the possibilities that can be achieved with Houdini worklets.

Craft interactive effects.
Create custom effects like particle systems, ripple animations, or even interactive text manipulation, all powered by worklet logic.

Extend visual styles.
Generate custom gradients, patterns, or even textures based on complex algorithms, all within the worklet environment.

Bridge the gap with JavaScript.
Integrate your existing JavaScript libraries and functionalities seamlessly into your CSS styles using worklet communication channels.

Getting Started with Worklets
As mentioned, worklets enable developers to create more complex and customizable effects in real-life applications. To illustrate further, let’s build a starry night effect using Houdini worklets:

<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<link rel=”stylesheet” href=”styles.css”>
<title>Starry Night Sky</title>
</head>
<body>
<section id=”night-sky”>
</section>
<script>
CSS.paintWorklet.addModule(‘./app.js’);
</script>
</body>
</html>

In the code snippet above, we prepare a dedicated section in the HTML, ready to accommodate the worklet effect when it’s implemented:

<script>
CSS.paintWorklet.addModule(‘./app.js’);
</script>

The line CSS.paintWorklet.addModule(‘./app.js’) tells the browser to grab the JavaScript code defining our paint worklet.

body {
margin: 0;
background-color: #000;
}

#night-sky {
width: 100vw;
height: 100vh;
background-image: paint(starrySky);
}

In the CSS code above, background-image: paint(starrySky) tells the #night-sky element to use our registered paint worklet named starrySky to generate the background instead of an image.

The JavaScript code below directly employs a standard loop and canvas drawing techniques to generate a varied starry sky effect with customizable colors, sizes, and random star positions:

class Star {
paint(ctx, geom, properties) {
const numStars = 100;
const starColors = properties.get(‘–star-colors’) || [‘white’, ‘grey’, ‘darkorange’];
const sizeRange = properties.get(‘–star-size-range’) || ‘2,3’;

for (let i = 0; i < numStars; i++) { const randomColor = starColors[Math.floor(Math.random() * starColors.length)]; const minSize = parseFloat(sizeRange.split(',')[0]); const maxSize = parseFloat(sizeRange.split(',')[1]); const starSize = Math.random() * (maxSize - minSize) + minSize; const x = Math.random() * geom.width; const y = Math.random() * geom.height; ctx.fillStyle = randomColor; ctx.beginPath(); ctx.arc(x, y, starSize, 0, 2 * Math.PI); ctx.fill(); ctx.closePath(); } } } registerPaint('starrySky', Star); Here are some things to note in the code above: - class Star: This defines our paint worklet, a blueprint for drawing a single star. - paint(ctx, geom, properties): This is the core of the worklet. ctx provides drawing tools, geom gives information about the element's size, and properties accesses our custom CSS properties for star colors and size. - Loop and randomness: We draw multiple stars in a loop, choosing their position and color randomly for a natural starry effect. - registerPaint('starrySky', Star): This registers our Star class as a paint worklet named starrySky, making it accessible from CSS. CSS Houdini Custom Properties Custom properties in CSS Houdini are advanced variables that offer enhanced control in web development. They go beyond traditional CSS variables, providing features like type checking, syntax definition, and custom logic for dynamic styling. A circular progress bar with custom rendering Let's dive into a practical example that showcases the power of paint worklets in creating visually captivating progress bars. This example focuses on a simple circular progress bar. The simple HTML structure below establishes the foundation for our progress bar. A

element with the class progress serves as the canvas, while the data-progress attribute dynamically stores the current progress value:

<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Moving Circular Progress Bar</title>
<link rel=”stylesheet” href=”styles.css”>
</head>
<body>
<div class=”progress” data-progress=”0″></div>
<script src=”app.js”></script>
</body>

The CSS snippet below utilizes Houdini’s custom properties to create a circular progress bar. The @property rule introduces –progress with a syntax, initialized at 0% and ensuring non-inheritance. The .progress class styles the circular container, utilizing a conic gradient to depict progress dynamically. This concise code harnesses the flexibility of Houdini custom properties for creating visually engaging circular progress elements in web development:

@property –progress {
syntax: ‘<percentage>’;
inherits: false;
initial-value: 0%;
}

.progress {
–progress: 0%;
width: 200px;
height: 200px;
border-radius: 50%;
background: conic-gradient(rgb(255, 58, 255) 0%, rgb(255, 58, 255) var(–progress), transparent var(–progress), transparent 100%);
position: relative;
overflow: hidden;
}

.progress::before {
content: attr(data-progress);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 24px;
font-weight: bolder;
color: purple;
text-align: center;
}

Next, we have the custom property definition (@property rule):

@property –progress {
syntax: ‘<percentage>’;
inherits: false;
initial-value: 0%;
}

Some things to note in the code above:

– The @property rule is part of the Houdini CSS Typed



Source link

Tags: AnimationBuildingcardcssFLIPHoudiniSitePoint
Previous Post

Learning the importance of training data under concept drift – Google Research Blog

Next Post

Boston Pizza Royalties Income Fund (BPZZF) Q4 2023 Earnings Call Transcript

Related Posts

Top 20 Javascript Libraries You Should Know in 2024
Cloud & Programming

Top 20 Javascript Libraries You Should Know in 2024

June 10, 2024
Simplify risk and compliance assessments with the new common control library in AWS Audit Manager
Cloud & Programming

Simplify risk and compliance assessments with the new common control library in AWS Audit Manager

June 6, 2024
Simplify Regular Expressions with RegExpBuilderJS
Cloud & Programming

Simplify Regular Expressions with RegExpBuilderJS

June 6, 2024
How to learn data visualization to accelerate your career
Cloud & Programming

How to learn data visualization to accelerate your career

June 6, 2024
BitTitan Announces Seasoned Tech Leader Aaron Wadsworth as General Manager
Cloud & Programming

BitTitan Announces Seasoned Tech Leader Aaron Wadsworth as General Manager

June 6, 2024
Copilot Studio turns to AI-powered workflows
Cloud & Programming

Copilot Studio turns to AI-powered workflows

June 6, 2024
Next Post
Boston Pizza Royalties Income Fund (BPZZF) Q4 2023 Earnings Call Transcript

Boston Pizza Royalties Income Fund (BPZZF) Q4 2023 Earnings Call Transcript

RBC unit City National Bank cuts nearly 100 jobs after financial losses By Reuters

RBC unit City National Bank cuts nearly 100 jobs after financial losses By Reuters

DANFOSS Radiator Valves with NeoMesh protocol – gilautomation

DANFOSS Radiator Valves with NeoMesh protocol – gilautomation

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
Is C.AI Down? Here Is What To Do Now

Is C.AI Down? Here Is What To Do Now

January 10, 2024
Porfo: Revolutionizing the Crypto Wallet Landscape

Porfo: Revolutionizing the Crypto Wallet Landscape

October 9, 2023
23 Plagiarism Facts and Statistics to Analyze Latest Trends

23 Plagiarism Facts and Statistics to Analyze Latest Trends

June 4, 2024
A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

May 19, 2024
Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

November 20, 2023
Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

December 6, 2023
Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

June 10, 2024
AI Compared: Which Assistant Is the Best?

AI Compared: Which Assistant Is the Best?

June 10, 2024
How insurance companies can use synthetic data to fight bias

How insurance companies can use synthetic data to fight bias

June 10, 2024
5 SLA metrics you should be monitoring

5 SLA metrics you should be monitoring

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

June 10, 2024
Facebook Twitter LinkedIn Pinterest RSS
News PouroverAI

The latest news and updates about the AI Technology and Latest Tech Updates around the world... PouroverAI keeps you in the loop.

CATEGORIES

  • AI Technology
  • Automation
  • Blockchain
  • Business
  • Cloud & Programming
  • Data Science & ML
  • Digital Marketing
  • Front-Tech
  • Uncategorized

SITEMAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2023 PouroverAI News.
PouroverAI News

No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing

Copyright © 2023 PouroverAI News.
PouroverAI News

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In