简体   繁体   English

无限滚动无法离线使用

[英]Infinite scrolling doesn't work offline

I am trying to learn jQuery and particularly jScroll from real examples. 我正在尝试从实际示例中学习jQuery,尤其是jScroll。 I found this website that might look silly to you but it's dead simple so it's a great example of jScroll work for me. 我发现这个网站对您来说可能看起来很愚蠢,但是它简直太简单了,因此这对我来说是jScroll工作的一个很好的例子。

The problem happens when I try to save the web page (Ctrl+S or just Save Page As) to my computer for offline use. 当我尝试将网页(Ctrl + S或仅将页面另存为)保存到计算机以供离线使用时,就会发生问题。 The scrolling doesn't work. 滚动不起作用。 It's just a static page. 这只是一个静态页面。 I've tried it both in Chrome and Firefox. 我已经在Chrome和Firefox中尝试过。

Does this happen to you too? 你也会这样吗? And if it does, is there an easy explanation of why it doesn't work? 如果可以的话,是否有一个简单的解释为什么它不起作用?

tl;dr The horse's legs are dynamically added via ajax requests from http://endless.horse/ which is a cross-origin http request and is therefore restricted for browser security reasons. tl; dr通过来自http://endless.horse/ ajax请求动态添加马的腿,这是一个跨域的http请求,因此出于浏览器安全性的原因而受到限制。 Also, you would need to be running a server to allow for ajax requests. 另外,您将需要运行服务器以允许ajax请求。

https://developer.chrome.com/extensions/xhr https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS https://developer.chrome.com/extensions/xhr https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

When the scroll event is fired it pulls in http://endless.horse/legs.html and appends it to the html to continuously "grow" the legs. 触发滚动事件后,它会拉入http://endless.horse/legs.html并将其附加到html上,以不断“增长”腿部。 There are two reasons it doesn't work locally: 它在本地不起作用有两个原因:

  1. Cross-origin HTTP Requests are disallowed for security reasons. 出于安全原因,不允许跨域HTTP请求。 https://developer.chrome.com/extensions/xhr https://developer.chrome.com/extensions/xhr
  2. You need to be running the html file through an HTTP server to have ajax working. 您需要通过HTTP服务器运行html文件才能使ajax正常工作。 After saving the page and opening it, the url begins with something like this file:/// - That's because you're opening the file directly and not running it through a web-server. 保存页面并打开后,URL以类似于以下file:/// -这是因为您是直接打开文件,而不是通过Web服务器运行它。

If you're running OSX or Linux you can create a simple server using python. 如果您正在运行OSX或Linux,则可以使用python创建一个简单的服务器。 1. Open up your terminal 2. cd /path/to/horse/project 3. python -m SimpleHTTPServer 5000 4. visit http://localhost:5000/ 1.打开终端2. cd /path/to/horse/project 3. python -m SimpleHTTPServer 5000 4.访问http:// localhost:5000 /

On Windows, download XAMPP and follow instructions. 在Windows上,下载XAMPP并按照说明进行操作。

Instead of using the "Save As" feature, create a new index.html at the root of the folder being served. 代替使用“另存为”功能,在要提供服务的文件夹的根目录下创建一个新的index.html View source on http://endless.horse/ copy/paste that into your new file. http://endless.horse/上查看源代码,将其复制/粘贴到新文件中。 The "Save As" feature does a lot of editing on the saved HTML file. “另存为”功能对保存的HTML文件进行了大量编辑。 You'll have to do this and make sure the index.html file links correctly to jquery.jscroll.js and the legs.html file. 您必须执行此操作,并确保index.html文件正确链接到jquery.jscroll.jslegs.html文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM