Jump to content

CSS animation in tag <a>


Eros eros

Recommended Posts

Hi, i have a div animated by CSS with a few tag <a> and when clicks on any of this tag <a> and take on new page at return would prefer that the animation not restart and so the page positioning on tag <a> clicked before.
Could be possible only using CSS?

Edited by Eros eros (see edit history)
Link to comment
Share on other sites

  • Eros eros changed the title to CSS animation in tag <a>

Hi,

It might not be possible to prevent animation restart and maintain scroll position using only CSS.

You need JavaScript for:

Preventing Animation Restart: Disable the animation when returning to the page using style.animation = 'none';.
Maintaining Scroll Position: Use sessionStorage to save and restore scroll position.

$(document).ready(function() {
if (performance.navigation.type === 2) {
$('.box').css('animation', 'none'); // Disable animation on return
}

$(window).scrollTop(sessionStorage.getItem('scrollPosition') || 0);

$(window).on('beforeunload', function() {
sessionStorage.setItem('scrollPosition', $(window).scrollTop());
});
});

Regards.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...