Eros eros Posted October 18 Share Posted October 18 (edited) 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 October 18 by Eros eros (see edit history) Link to comment Share on other sites More sharing options...
Knowband Plugins Posted October 19 Share Posted October 19 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now