#View Transitions Scaling with grid

21 messages · Page 1 of 1 (latest)

grand moonBOT
#

Hi @hollow goblet. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Hmm, I don't know enough to give you a confident answer yet. However, Astro's View Transitions API is designed to provide seamless animations between pages. It supports a few built-in animation options such as fade, slide, and none, and also allows you to fully customize all aspects of transition animation.

If you're experiencing issues with the scaling of elements during transitions, it might be related to how you've set up your animations or the specific CSS properties of your grid elements.

You might find it helpful to review the Astro documentation on View Transitions (https://docs.astro.build/en/guides/view-transitions/) for more information on how to control and customize these animations. If the issue persists, consider raising an issue on the Astro GitHub page (https://github.com/withastro/astro/issues) for further assistance.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@hollow goblet kapa.ai is still learning and improving, please let us know how it did by reacting below

hollow goblet
#

@grand moon Here's my CSS for the first page: .grid {
display: grid;
width: 500px;
height: 900px;
grid-template-columns: repeat(3, 1fr);
background-color: green;
}
.test1 {

    background-color:blue;
    grid-column: span 2;
}

and Here's my CSS for the second page:

.grid {
display: grid;
width: 500px;
height: 900px;
grid-template-columns: repeat(3, 1fr);
background-color: green;
}
.test1 {

    background-color:blue;
    grid-column: span 1;
}

does it make sense that this wouldn't work properly? I'm trying to get the .test1 div on each page to scale seamlessly

grand moonBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Based on the CSS you've provided, it seems like you're trying to transition a grid item (.test1) from spanning 2 columns on the first page to spanning 1 column on the second page.

Astro's View Transitions API is designed to handle transitions between pages, but it might not be able to handle transitions of CSS grid properties directly. The grid-column property, which you're trying to transition, affects the layout of the grid and might not be directly animatable.

One possible workaround could be to use JavaScript to handle the transition of the grid-column property. You could listen for the page transition event and then apply a CSS transition to the grid-column property of the .test1 element.

However, this is just a suggestion and might not work as expected. For more specific guidance, you might want to raise an issue on the Astro GitHub page (https://github.com/withastro/astro/issues) and provide the details of your use case. The Astro community or the Astro team might be able to provide more specific advice or solutions.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@hollow goblet kapa.ai is still learning and improving, please let us know how it did by reacting below

hollow goblet
#

@grand moon would it be possible to do this if instead of the element on both pages being inside of a grid, the element was in a grid on one page and just a normal block element controlled by width and height on another?

grand moonBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Yes, it should be possible to transition an element from being a grid item on one page to a normal block element on another page using Astro's View Transitions API.

The key is to ensure that the transitioning element (.test1 in your case) is present on both pages and has a consistent transition:name directive. This allows Astro to identify the corresponding elements on the old and new pages and apply the transition.

Here's an example of how you might set this up:

On the first page (grid layout):

<div class="grid">
  <div class="test1" transition:name="test">...</div>
</div>

And on the second page (block layout):

<div class="test1" transition:name="test" style="width: 100px; height: 100px;">...</div>

In this setup, the .test1 element would transition from being a grid item on the first page to a block element on the second page. You can customize the transition animation using Astro's built-in animation directives or create your own animations.

Remember to import and add the <ViewTransitions /> component to the <head> of each page to enable view transitions.

Please note that this is a general guide and the actual implementation might need to be adjusted based on your specific use case and layout. For more information, you can refer to the Astro documentation on View Transitions (https://docs.astro.build/en/guides/view-transitions/).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@hollow goblet kapa.ai is still learning and improving, please let us know how it did by reacting below

hollow goblet
#

@grand moon so the transition does happen and it is scaling correctly on the x axis, but the y axis is not lining up between the two pages and there's a clear crossfade as it scales

grand moonBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Astro's View Transitions API provides a way to animate transitions between pages, but it might not handle all types of transitions perfectly, especially when it comes to complex layout changes.

In your case, it seems like the transition is working correctly on the x-axis, but not on the y-axis. This could be due to the differences in the layout or the CSS properties of the .test1 element on the two pages.

One possible workaround could be to manually control the transition of the .test1 element's height using CSS transitions. You could add a CSS transition to the height property of the .test1 element and then adjust the height value based on the page.

Here's an example:

.test1 {
  transition: height 0.3s ease;
}

Then, on the first page (grid layout):

.test1 {
  height: 200px; /* adjust as needed */
}

And on the second page (block layout):

.test1 {
  height: 100px; /* adjust as needed */
}

This will create a smooth transition of the .test1 element's height as you navigate between the two pages.

Please note that this is a general suggestion and might not work perfectly in all cases. For more specific guidance, you might want to raise an issue on the Astro GitHub page (https://github.com/withastro/astro/issues) and provide the details of your use case. The Astro community or the Astro team might be able to provide more specific advice or solutions.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@hollow goblet kapa.ai is still learning and improving, please let us know how it did by reacting below

hollow goblet
#

@grand moon To be clear, these are two separate divs with two separate classes both called test1 on each page, and the only way they are linked is with transition:name in the view:transitoins API.

grand moonBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Yes, that's correct. The transition:name directive is what links the two separate div elements with the class test1 on each page.

Astro's View Transitions API uses the transition:name directive to identify corresponding elements on the old and new pages. When you navigate from one page to another, Astro will automatically assign a shared, unique view-transition-name to the pair of matching elements. This allows Astro to animate the transition between these elements.

Here's an example:

On the first page:

<div class="test1" transition:name="test">...</div>

And on the second page:

<div class="test1" transition:name="test">...</div>

In this setup, the div elements with the class test1 on both pages are linked by the transition:name directive, and Astro will animate the transition between these elements when you navigate from the first page to the second page.

For more information, you can refer to the Astro documentation on View Transitions (https://docs.astro.build/en/guides/view-transitions/).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@hollow goblet kapa.ai is still learning and improving, please let us know how it did by reacting below

hollow goblet
#

@grand moon So given that these are two separate divs on different pages linked only with the view transitions API, how would I be able to use CSS transitions to manually control the transition?

grand moonBOT
#

Let me check the knowledge base for you. One moment! :books: