如何使用箭头键在浏览器中重新加载新的 URl
Facebook 和 myspace 都有一个很好的照片库功能,当您进入图像页面时,页面上会显示用户的图像和用户评论。您可以点击键盘的左右箭头键,页面将加载下一页,它的速度非常快,如果您按住该键,它会快速浏览许多页面。我知道这主要是用 JavaScript 实现的,我的主要问题是如何让新页面加载得很快?
我使用 PHP/mysql/Javascript
Facebook and myspace both have a nice feature in the photo galleries, when you go to an image page, a page with the user's image and user comments on the page. You can hit you keyboard left and right arrow key and the page will load the next page, it does it super fast, if you held down the key it would go fast through many pages. I know this is mostly with javascript, my main question is how to make the new pages load all soo quickly?
Im using PHP/mysql/Javascript
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将捕获用户按下的按键以及左箭头和右箭头的响应。捕获密钥并不那么困难:
您希望根据自己的喜好调整该代码。如果单击的是右箭头,则发出对
get-image.php?direction=next&user=12838203
的请求,如果是后退箭头,只需将“next”替换为“prev” ”。You'd capture the keys the user is pressing, and response for left-arrows and right-arrows. Capturing keys isn't all that difficult:
You'd want to adapt that code to your liking. If the right arrow was click, fire off a request to
get-image.php?direction=next&user=12838203
and if it were the back-arrow, simply swap out "next" for "prev".它们实际上并没有加载页面,而只是使用 Ajax。
这就是全部 - 当您按下按钮时,它们会动态加载图像。您可以在 Facebook 中通过开放的 Firebug< /a> 在“网络”选项卡中。
如果您喜欢 JQuery,JQuery Ajax 页面是一个不错的起点观点。
您可以查看流行的 灯箱脚本用于实际示例。
They are not actually loading pages, but only parts of it using Ajax.
That's all there is to it - they are loading the images on the fly as you press the buttons. You can watch that in Facebook with an open Firebug in the "Net" tab.
If you're into JQuery, the JQuery Ajax page is a good starting point.
You could look into the source code of one of the popular lightbox scripts for real-world examples.