用JS检测后退和前进按钮
我有一个网站设计,我希望页面在您从一个页面导航到另一个页面时进行淡入淡出过渡。我正在研究一种复杂的方法来使用 jQuery.load 和哈希标签 url 等。然后我意识到,可以通过简单地拦截链接点击、运行淡入淡出动画然后重定向到链接页面(设置为淡入)来实现更简单的解决方案。无需使用 ajax 并在一个页面内运行所有内容。
我只有一个小问题。如果用户单击前进或后退按钮,或使用键盘达到相同的效果...如何触发淡入淡出动画?我知道您可以使用 jQuery('window').unload() 但我不知道我是要后退还是前进,还是只是刷新页面。这很重要,因为淡入淡出动画实际上需要淡出背景以匹配其将要出现的页面。
I have a site design where I want pages to do a fading transition as you navigate from page to page. I had a sophisticated method I was working out to use jQuery.load
and hash tag urls and such. Then I realized that a much simpler solution could be achieved by simply intercepting link clicks, running a fade animation and then redirecting to the linked page (which is set to fade itself in). No need to use ajax and run everything from within one page.
I have just one small problem. If a user clicks forward or back buttons, or uses the keyboard to the same effect...how do I trigger the fade animation? I know you can use jQuery('window').unload()
but then I don't know if I am going back or forward or just refreshing the page. This is critical because the fade animation actually needs to fade the background to match the page that it is going to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需隐藏正文,然后淡入:)
关键是打开:
您可以查看以下链接以获得更多帮助:
如何使用 jQuery 制作 Slick 页面过渡
页面淡入淡出效果与 Jquery
第一个链接更好:)
编辑:您可以查看评论以获取更多信息,但我的结果是:
如果您使用热键返回页面,或者
history.back()
或history.forward()
可能.fadeIn()
效果不再起作用,您可以尝试以下代码重做 fadeIn 效果:但如果您尝试使用 :
或:
fadeOut 将不起作用,即使代码在语法上是正确的,搜索后,似乎是因为:
此引用来自 Jquery, FadeIn before unload 的答案。
Simply hide body and then fadeIn :)
the key is on :
You can see the follwoing links for more help:
How to Use jQuery to Make Slick Page Transitions
Page Fade In effect with Jquery
First Link is better :)
Edit: you can see comments for more info, but my result is :
If you back to page using hotkeys, or
history.back()
orhistory.forward()
maybe the.fadeIn()
effect will not work again, you can try the following code to redo fadeIn effect :But if you tried use :
or:
the fadeOut will not work even the code syntactically is correct, after search, seemes that because:
This quotation from answer of Jquery, FadeIn before unload .
这是非常链接,其中包含键盘事件的实时示例,如果您合并有了@Al-Mothafar 的回答,一切就完成了:)
Here is very link with live example for keyboards events, if you merge with @Al-Mothafar answer, it will be complete :)