如何使用箭头键在浏览器中重新加载新的 URl

发布于 2024-08-17 04:01:34 字数 192 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慢慢从新开始 2024-08-24 04:01:34

您将捕获用户按下的按键以及左箭头和右箭头的响应。捕获密钥并不那么困难:

$(window).bind("keypress", function(e) {
  var code = (e.keyCode ? e.keyCode : e.which); // which code?
  alert(String.fromCharCode(code)); // which key, according to the code?
});

您希望根据自己的喜好调整该代码。如果单击的是右箭头,则发出对 get-image.php?direction=next&user=12838203 的请求,如果是后退箭头,只需将“next”替换为“prev” ”。

$("#loading").show(); // fancy ajax loading animation
$.post("get-image.php", {direction:"next",user:12838203}, function(response){
  // hide our ajax loading animation
  $("#loading").hide();
  // if we get a proper response, like a source for a new image back
  $("#image").fadeOut("fast").attr("src", response).fadeIn("fast");
});

You'd capture the keys the user is pressing, and response for left-arrows and right-arrows. Capturing keys isn't all that difficult:

$(window).bind("keypress", function(e) {
  var code = (e.keyCode ? e.keyCode : e.which); // which code?
  alert(String.fromCharCode(code)); // which key, according to the code?
});

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".

$("#loading").show(); // fancy ajax loading animation
$.post("get-image.php", {direction:"next",user:12838203}, function(response){
  // hide our ajax loading animation
  $("#loading").hide();
  // if we get a proper response, like a source for a new image back
  $("#image").fadeOut("fast").attr("src", response).fadeIn("fast");
});
彼岸花似海 2024-08-24 04:01:34

它们实际上并没有加载页面,而只是使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文