admin管理员组文章数量:1391937
I need a few objects on my pages to animate out when a user clicks a link. I want each object to scale and fade out but not all objects such as the navigation buttons.
I was thinking that upon a user clicking a link, the page delays 1 second before opening the redirecting the link to allow fade out giving the animation time to take effect.
I need a few objects on my pages to animate out when a user clicks a link. I want each object to scale and fade out but not all objects such as the navigation buttons.
I was thinking that upon a user clicking a link, the page delays 1 second before opening the redirecting the link to allow fade out giving the animation time to take effect.
Share Improve this question edited Sep 18, 2013 at 13:55 Alex Shesterov 27.6k14 gold badges89 silver badges108 bronze badges asked Sep 18, 2013 at 13:29 user2761443user2761443 2- could you show your attempts in a fiddle? – Fabrizio Calderan Commented Sep 18, 2013 at 13:34
- Take a look at below web site on Using CSS transitions. developer.mozilla/en-US/docs/Web/Guide/CSS/… – Jocelyn Commented Sep 18, 2013 at 13:44
1 Answer
Reset to default 5Look at the JS event window.onbeforeunload
https://developer.mozilla/en-US/docs/Web/API/window.onbeforeunload
It will hopefully be enough to just run the exit animations when this function is triggered - it generally takes the browser around a second to unload the page pletely but this varies depending on your browser, page size and cpu speed.
Assuming you're using plain JS and you know how to do CSS transitions, the simple way to make animations occur on page exit is something like this:
window.onbeforeunload = function(e){
document.getElementById('myDiv').className = 'out';
}
Where myDiv
id the element you want to animate and out
is the CSS class representing the final stage of your transition.
Here is a JSfiddle: http://jsfiddle/X5vKS/
If you need finer control over the wait time, you could use the onbeforeunload
function with setTimeout
to delay the page exit by the length of time of your animation. This is slightly plex for a JS beginner but is quite doable.
本文标签: javascriptCSS transition property on page exitStack Overflow
版权声明:本文标题:javascript - CSS transition property on page exit - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744689680a2619917.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论