简体   繁体   English

Jquery,Django,Infinite Scroll在加载页面后加载其余元素

[英]Jquery, Django, Infinite Scroll load rest of elements after page is loaded

I was able to implement infinite scrolling into my Django website's home page following this guide: https://simpleisbetterthancomplex.com/tutorial/2017/03/13/how-to-create-infinite-scroll-with-django.html 我能够按照本指南实现无限滚动到我的Django网站的主页: https//simpleisbetterthancomplex.com/tutorial/2017/03/13/how-to-create-infinite-scroll-with-django.html

Basically the Jquery code that triggers the infinite scroll is this (plus some django code): 基本上,触发无限滚动的Jquery代码是这样的(加上一些Django代码):

<script>
  var infinite = new Waypoint.Infinite({
  element: $('.infinite-container')[0]
  });
</script>

This is good because I load the page pretty quickly and the user is then able to infinite scroll as the other elements load. 这很好,因为我很快加载了页面,然后用户可以在其他元素加载时无限滚动。 What I want to achieve now is to load the page like I do now and immediately after, without the need of scrolling down, I want to load the rest of the elements. 我现在想要实现的是像现在一样加载页面,之后立即加载页面,而不需要向下滚动,我想加载其余的元素。 So basically load the page with the first few elements and then load all the remaining elements without having to scroll. 因此,基本上先加载页面的前几个元素,然后加载所有其余元素,而无需滚动。 Note that I have used the above guide's implementation as it is a convenient way of being able to use all of Django's power (especially related to foreign keys), so I am trying to stick to this approach. 请注意,我使用了上面的指南实现,因为它是一种方便的方式,可以使用所有Django的功能(特别是与外键相关),所以我试图坚持这种方法。

Is there a way to do so changing the what the Jquery is triggered only? 有没有办法改变Jquery只触发的内容?

Thanks, Vittorio 谢谢,维托里奥

Waypoint.Infinite is a lib you should be reading docs for. Waypoint.Infinite是一个你应该阅读docs的lib。 Assuming loading is triggered on reaching bottom, you can just scroll to bottom with Jquery on page load. 假设加载到达底部时触发,则可以使用页面加载时的Jquery滚动到底部。

$('html, body').scrollTop($(document).height());

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

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