[目标:我正在尝试使用具有合理布局,无限滚动和灯箱的Django构建照片库应用。
我使用django分页和waypoint.js跟随了following tutorial进行无限滚动,合理的布局使用了Justified Gallery,我尝试将Fancybox用作灯箱(任何灯箱都可以做到这一点,但是我像这个的干净外观)。在这一点上,当单独使用时,它们每个都可以正常工作。
问题:我的相册包含100张图像。在桌面上加载页面时,将加载36。如果我向下滚动,则正确加载了下一页/图像。但是,如果我在滚动之前使用灯箱,则会被这36张图像卡住。因此,目前,我主要是在寻找一种方法来触发灯箱图库中页面的延迟加载,而不必退出灯箱并向下滚动。
[我发现许多关于将新图像包括到灯箱中的stackoverflow帖子(这可能是我的下一个挑战,TBH,但关于如何从灯箱中调用下一页/图像的信息不多。
作为某种js / jQuery noob,欢迎您提供任何帮助,因为我什至不确定这是否是正确的方法。
[这里,您会找到gallery.html页面的模板。显然,这不是一个“最小的可复制示例”,因为它可能是整个应用程序(如果需要,仍然可能),但是如果需要,我可以提供更多代码。
{% load static %}
{% block head %}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<!-- scripts used for the justified layout -->
<link rel="stylesheet" href="{% static 'gallery/justified-gallery/justifiedGallery.min.css' %}">
<script src="{% static 'gallery/justified-gallery/jquery.justifiedGallery.min.js' %}"></script>
<!-- scripts used for the infinite scrolling -->
<script src="{% static 'gallery/js/jquery.waypoints.min.js' %}"></script>
<script src="{% static 'gallery/js/infinite.min.js' %}"></script>
<!-- scripts used for the lightbox -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/[email protected]/dist/jquery.fancybox.min.css"/>
<script src="https://cdn.jsdelivr.net/gh/fancyapps/[email protected]/dist/jquery.fancybox.min.js"></script>
{% endblock %}
{% block content %}
<div style="margin-left: 100px; margin-right: 100px;">
<div class="infinite-container justified-gallery" id="my_gallery">
{% for picture in pictures %}
<div class="infinite-item">
<a href={{ picture.picture.url }} data-fancybox="gallery">
<img alt=" caption for image 1" src={{ picture.picture_thumbnail.url }}/>
</a>
</div>
{% endfor %}
</div>
<div class="loading" style="display: none;">
Loading...
</div>
{% if page_obj.has_next %}
<a class="infinite-more-link" href="?page={{ page_obj.next_page_number }}">More</a>
{% endif %}
</div>
{% endblock %}
{% block script %}
<script>
// Initialize the justified layout
$('#my_gallery').justifiedGallery({
rowHeight: 280,
lastRow: 'nojustify',
margins: 20
});
var infinite = new Waypoint.Infinite({
element: $('.infinite-container')[0],
onBeforePageLoad: function () {
$('.loading').show();
},
onAfterPageLoad: function ($items) {
$('.loading').hide();
// re-organize layout after loading
$('#my_gallery').justifiedGallery('norewind');
}
});
</script>{% endblock %}
ps:这是我的第一个stackoverflow帖子,不要犹豫,告诉我是否需要调整任何内容在此先感谢
fancybox提供了回调,使您可以在工作流中的任何时候执行代码,例如,在加载图像之前/之后,您可以在文档中找到示例-https://fancyapps.com/fancybox/3/docs/#events
无论如何,100张图像并不是什么大问题,因为同时只有3张幻灯片(当前和下一张/上一张),因此我不确定是否值得进行这样的尝试。