[英]How to lazy load list items with onclick()?
I am trying to mimic an ajax feel to loading multiple list items using jquery. 我试图模仿使用jquery加载多个列表项的ajax感觉。
Ultimately i would like to show 10 items and then 10 more after clicking "Load More" button. 最后,我想显示10个项目,然后点击“加载更多”按钮后再显示10个项目。
My code: 我的代码:
<ul id="listings-container">
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
<li>List item ...</li>
</ul>
<a class="button" href="#">Load More</a>
I tried this, simplest way to lazy load long <ul> with many <li>s 我尝试了这个, 最简单的方法来延迟加载long <ul>和许多<li>
I am trying to accomplish similar with click rather than scroll. 我试图用点击而不是滚动来完成类似的事情。
Any ideas? 有任何想法吗?
Just in case if you're using bootstrap tab panel and lazy loading , it works well for loading the first tab (default active) but not for when you clicked to other tabs, images will not load unless you scroll. 如果您正在使用引导选项卡面板和延迟加载 ,它适用于加载第一个选项卡(默认活动)但不适用于您单击其他选项卡时,除非您滚动,否则不会加载图像。
Here is a workaround for this issue, just add the below javascript and you'll be fine. 以下是此问题的解决方法,只需添加以下javascript,您就可以了。 The logic is simple, when the tab is clicked, trigger a scroll.
逻辑很简单,单击选项卡时会触发滚动。
$(document).ready(function () {
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
$(window).trigger('scroll');
});
});
For more information about shown.bs.tab
and other functions please refer to this link: http://www.w3schools.com/bootstrap/bootstrap_ref_js_tab.asp 有关
shown.bs.tab
和其他功能的更多信息,请参阅此链接: http : //www.w3schools.com/bootstrap/bootstrap_ref_js_tab.asp
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.