How do you make an infinite scroll page in Blogger?

假装没事ソ 提交于 2020-01-02 01:55:27

问题


I have a blog and would like to make it infinite scroll so you don't have to click through pages and pages of posts. Can anyone help me with the code, its in HTML according to Blogger? Thanks :-)


回答1:


How to add infinite scrolling to Blogger blogs

Recently I read an interesting article, How to add infinite scrolling to Blogger blogs. If you are using Blogger's blog, you can follow the instructions and give your blog, an infinite scroll without much hassle.

The code for the widget is available on Google Code. Feel free to copy or adapt the code.

From their website, a few points worth mentioning:

  • This code uses jQuery library, so don’t forget to include it.
  • Custom template blogs may have to change the value of postContainerSelector variable in the code.
  • You have manually added +1 buttons to my blog. Dynamically loaded posts won’t have the +1 buttons initialised; to fix that issue, I had to call gapi.plusone.go() every time new posts are added to the page.
  • _WidgetManager is a JavaScript object present in Blogger blogs. You can query this object to find some page metadata. This code uses _WidgetManager to determine if the current page is showing a single post. Infinite scrolling is not meaningful when only a single post needs to be displayed.



回答2:


HTML has no way of achieving this, you need JavaScript.

First set up an event listener for the scroll event. When it fires compare the distance scrolled to the height of the document and window.

If that indicates you are near the document, use XMLHttpRequest to download more content, and then the usual DOM suspects to add that content to the page.




回答3:


You can achieve this thru JQuery or JScript. HTML can not do this alone.

Here is some example how you can get this.




回答4:


HTML doesn't specify absolutes in terms of height as it automatically allows for infinite scrolling (you can't say height="100%" for instance. In terms of CMS Blogs like blogger there should be user preferences available to say how many posts you want displayed, in the control panel. Alternatively if you are using a server side technology (e.g. php) with a database you can specify number of items displayed using record set paging.




回答5:


You need to add an event listener using JavaScript, means when a particular element comes to view port an event is fired and it fetches the data from some external resources. The data comes in JSON and you need to extract it and append the info in a DIV.
For this I have made a script which fetches the data from Google Docs using Jquery and the event is fired after you scroll to the bottom most portion. You can check the infinite scroll here



来源:https://stackoverflow.com/questions/12872070/how-do-you-make-an-infinite-scroll-page-in-blogger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!