html 文档之间的多向滚动

发布于 2024-11-05 19:51:59 字数 178 浏览 0 评论 0原文

我一直在使用 jquery 进行多向滚动。我发现这是一种浏览网站的绝佳方式,但它有一个缺点。浏览器需要一次加载所有网站内容,因为它位于一个 html 文档中。

现在我一直在寻找一种在不同 html 文档之间进行出色滚动的方法,但没有成功。因此,我想知道是否可以在 html 文档之间滚动,而不是在 div 之间滚动。这可能吗?

I've been playing around with multi directional scrolling with jquery. I find this is a superb way to navigate through a website, but it has one drawback. The browser needs to load all site content at once because it's in one html document.

Now I have been searching unsuccessfully for a way to have this great scrolling between different html documents. So instead of scrolling between div's I wonder if it is possible to scroll between html documents. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

笑,眼淚并存 2024-11-12 19:51:59

这在客户端和服务器之间的请求/响应事务处理方式的正常意义上是不可能的 - 只有浏览器可以在此页面更改级别上动画更改。还有一些其他选项:

  1. 当您滚动到一侧时,使用 JS 将浏览器重定向到下一页(使用一些哈希标签或信息查询字符串)。当下一页加载时,您应用一个动画,使其看起来像是已滚动进入。这有一个令人讨厌的缺点,即页面转换之间存在延迟。
  2. 使用 AJAX,因此当您滚动时,内容会异步加载到页面中。然后,一旦加载完毕,您就不必担心。这与您在图像搜索中滚动浏览图像时 Google 或 Bing 的操作类似。这样做的优点是只加载您需要的内容。

对于AJAX加载,jQuery的AJAX方法非常有用: http://api.jquery.com/jQuery.ajax /
只需传入 URL、您想要的任何信息和回调即可。在回调中,将响应数据加载到空 div 或任何位置。
像这个例子,取自 jQuery 的网站:

    $.ajax({
  url: 'ajax/test.html',
  success: function(data) {
    $('.result').html(data);
    alert('Load was performed.');
  }
});

This isn't possible in the normal sense of how Request/Response transaction between a client and a server - only a browser could animate changes on this page-change level. There are some other options:

  1. When you scroll off to one side, use JS to redirect the browser (with some hash tags or query strings for info) to the next page. When the next page loads, you apply an animation that makes it look like it's been scrolled into. This has the nasty disadvantage of have a delay between page transitions.
  2. use AJAX, so, when you scroll, content is asynchronously loaded into the page. Then, once it's loaded, you don't have to worry about it. This is similar to what Google or Bing do when you're scrolling through images in an image search. This has the advantage of loading only what you need.

For AJAX loading, jQuery's AJAX method is very useful: http://api.jquery.com/jQuery.ajax/
Simply pass in a URL, any info you want, and a callback. On the callback, load the response data into an empty div or wherever.
Something like this example, taking from jQuery's site:

    $.ajax({
  url: 'ajax/test.html',
  success: function(data) {
    $('.result').html(data);
    alert('Load was performed.');
  }
});
若水般的淡然安静女子 2024-11-12 19:51:59

有两种方法可以实现这一目标。

  • 使用 iframe。这显然不是最好的选择。
  • 二是让DIV中的所有链接都使用ajax,将内容加载到DIV中。基本上,修改所有链接,使其实际上不会去任何地方,而是在页面上动态加载到相应的 DIV 中。

There are two ways that you could get this accomplished.

  • Use iframes. This is obviously not the best choice.
  • The second is to make all links in the DIV use ajax and load content into the DIV. Basically, modify all of the links to not actually go anywhere, but to load dynamically on the page into the respective DIV.
嘿咻 2024-11-12 19:51:59

是的,如果您将其他 html 页面预加载到 div 或 iframe(例如)。

Yes, if you preload other html pages to divs or iframes (for example).

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