DEV Community

Cover image for Creating Smooth Tab Transitions with the View Transitions API

Creating Smooth Tab Transitions with the View Transitions API

Rodrigo Antunes on April 08, 2024

TL;DR The codepen is at the end of the post Let's build this: ⚠️Important Before diving into how to make this, it's important to note ...
Collapse
 
guiteixeira profile image
Guilherme Teixeira

AWESOME!!!!!!!!!!!!!!!!!!!!!!!!!!!

Collapse
 
phongpticdvn profile image
phongpticdvn

how about 'hover event', ex: mouseenter/mouseleave? I dont see any result in the Internet T_T

Collapse
 
rodrigoantunes profile image
Rodrigo Antunes • Edited

Hey @phongpticdvn, thanks for the message.
If you change the eventListener to mouseenter, it should work when hover the button, like this button.addEventListener('mouseenter', .... (on line 4)

But I'm not sure if that is what you need, you have an example to illustrate the effect you are trying to do?

Collapse
 
phongpticdvn profile image
phongpticdvn • Edited

I know that but the event i triggered continously, try it at: w3schools.com/tags/tryit.asp?filen...
with this script code:
const details = document.querySelector('details')
const summary = document.querySelector('summary')
summary.addEventListener('mouseenter', (event) => {
console.log(event)
event.preventDefault()
document.startViewTransition(() => {
details.setAttribute('open', '')
})
})

Thread Thread
 
rodrigoantunes profile image
Rodrigo Antunes

I think you want to animate the element when open/close, right?
I didn't try that yet. Although I found a blog post on dealing with this animated element, here: css-tricks.com/how-to-animate-the-...
It uses the Web Animation API insted of View Transition API, but maybe is this the effect you are looking for, and it will work in all browsers, hope it helps

Thread Thread
 
rodrigoantunes profile image
Rodrigo Antunes