Friday, May 9, 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

View Transitions in Astro — SitePoint

January 24, 2024
in Cloud & Programming
Reading Time: 2 mins read
0 0
A A
0
Share on FacebookShare on Twitter


This introduction to view transitions in Astro is excepted from Unleashing the Power of Astro, available now on SitePoint Premium.

The View Transitions API offers a convenient way to generate animated transitions between various DOM states while simultaneously updating the DOM content in a single operation. Achieving this has traditionally been difficult on the Web, but with this new API, transitions can be handled in a rather easy way. Studies have shown that using the View Transitions API leads to a faster perceived site performance.

Astro supports view transitions out of the box, with a built-in fallback mechanism for browsers that don’t currently support the API.

The out-of-the-box solution supports built-in animations, animations for forward and backward navigation, and automatic support for accessibility (via prefers-reduced-motion), amongst many other things.

One of the best ways to demonstrate view transitions is to utilize a video element that will maintain its state between page transitions. (Do note that we can also persist state between components that utilize the client:* directives as well.) An example of this is shown in the video below.

Let’s assume that we have a <Video /> component with this content:

—
// src/components/Video
const src=”https://res.cloudinary.com/tamas-demo/video/upload/f_auto,q_auto/imagecon/ship.mp4″;
const {
autoplay = false,
controls = true,
loop = false
} = Astro.props;
—

<video {controls} {autoplay} {loop} transition:persist>
<source {src} />
</video>

In the code above, we’re grabbing a video from Cloudinary. Additionally, we’re allowing the video to automatically play and loop (start over) when it finishes, and we’re providing control buttons for the user. These settings are determined by properties sent to this video component, and if these properties aren’t provided, default values are used. These variables are then added to the HTML <video> and <source> elements.

Please take note of the transition:persist directive. With this directive, we’ll maintain the state of the video player between transitions: while navigating to the next page, the video will keep on playing, while other parts of the page will show the updated content. We can use this component on both the index.astro and about.astro pages:

// src/pages/index.astro
—
import Video from ‘../components/Video.astro’;
—
<!– some other HTML –>
<Video />

Lastly, we need to enable page transitions, which we can either do per page or globally for the entire project. Assuming that we have a layout file of some sort, we can easily enable it, by importing ViewTransitions from astro:transitions:

// src/layouts/Layout.astro
—
import { ViewTransitions } from ‘astro:transitions’;
—
<html lang=”en”>
<head>
<title>My site!</title>
<ViewTransitions />
</head>
<body>
<slot />
</body>
</html>

In summary, the experimental View Transitions API simplifies visual transitions between various pages or elements through CSS pseudo-elements, JavaScript, and snapshots of the previous and current DOM states. It presents a fresh chance to enhance the perceived performance of a page, minimizing reliance on intricate custom JavaScript and CSS.

Want to learn more about Astro, the modern all-in-one framework to build faster, content-focused websites? Check out Unleashing the Power of Astro, available now on SitePoint Premium.



Source link

Tags: AstroSitePointTransitionsview
Previous Post

San Francisco files lawsuit to pump brakes on robotaxis

Next Post

Generating the policy of tomorrow | MIT News

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
Generating the policy of tomorrow | MIT News

Generating the policy of tomorrow | MIT News

Fireworks AI Open Sources FireLLaVA: A Commercially-Usable Version of the LLaVA Model Leveraging Only OSS Models for Data Generation and Training

Fireworks AI Open Sources FireLLaVA: A Commercially-Usable Version of the LLaVA Model Leveraging Only OSS Models for Data Generation and Training

Wait Until Earnings, but Be Ready

Wait Until Earnings, but Be Ready

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
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
A faster, better way to prevent an AI chatbot from giving toxic responses | MIT News

A faster, better way to prevent an AI chatbot from giving toxic responses | MIT News

April 10, 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