javascript Facebook如何实现无限滚动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10404699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does Facebook achieve infinite scrolling?
提问by Hoa
My first question is how do they get this scroll bar?
我的第一个问题是他们如何获得这个滚动条?
http://dl.dropbox.com/u/12337149/scrollbar.png
http://dl.dropbox.com/u/12337149/scrollbar.png
I have seen it in a few places so I presume it might be in a public library? My second question relates to the infinite scrolling itself. Once again I have seen it on a few sites so is it a technique that is relatively common and is described somewhere?
我在几个地方见过它,所以我认为它可能在公共图书馆?我的第二个问题与无限滚动本身有关。我又一次在几个网站上看到了它,所以它是一种相对常见并在某处描述的技术吗?
回答by Nathan
Do you mean the "lazy load" effect like on Twitter (when you scroll, it loads more when you reach the bottom)? They use AJAX (Asynchronous JavaScript and XML)and measure when you reach the bottom and load more data. But they use JSON since it is easier to most people than XML (but it is still called AJAX).
你的意思是像 Twitter 上的“延迟加载”效果(当你滚动时,它会在你到达底部时加载更多)?他们使用AJAX(异步 JavaScript 和 XML)并在您到达底部并加载更多数据时进行测量。但是他们使用 JSON,因为它比 XML 对大多数人来说更容易(但它仍然被称为 AJAX)。
There is a jQuery plugin for that called Infinite Scroll.
有一个名为Infinite Scroll的 jQuery 插件。
Also for the scroll bar thing, those are like Mac OS X Lion's scrollbar (which is most likely where they got the idea from), here's another Stack Overflow postabout it.
同样对于滚动条,它们就像 Mac OS X Lion 的滚动条(这很可能是他们获得想法的地方),这是关于它的另一篇Stack Overflow 帖子。
I hope this helps give you some information about this stuff.
我希望这有助于为您提供有关此内容的一些信息。
And by the way if you don't know what jQuery is, it is an awesome library for JavaScript and makes everything faster to code in JavaScript. You should check it out at jQuery.comif you never used it/heard of it.
顺便说一句,如果你不知道 jQuery 是什么,它是一个很棒的 JavaScript 库,可以让一切都更快地用 JavaScript 编码。如果您从未使用过/听说过它,则应该在jQuery.com 上查看它。
回答by ninjagecko
AJAX (often implemented with the XmlHttpRequest primitive; actually using the JSON format instead of Xml) is the act of making a server request in javascript without reloading the page, and registering a callback to handle the response. When the response arrives, the callback is invoked with the data, like a page fetch, but without reloading the page.
AJAX(通常使用 XmlHttpRequest 原语实现;实际上使用 JSON 格式而不是 Xml)是在不重新加载页面的情况下在 javascript 中发出服务器请求,并注册一个回调来处理响应的行为。当响应到达时,将使用数据调用回调,就像页面获取一样,但不会重新加载页面。