Difference between revisions of "Auto load content on scroll"
From UnionCloud Support
(Page creation) |
(Change to else ifs) |
||
Line 23: | Line 23: | ||
if (window.location.pathname.substring(0, 7) == '/events' && window.location.pathname.length <= 8) { | if (window.location.pathname.substring(0, 7) == '/events' && window.location.pathname.length <= 8) { | ||
EnableAutoLoadMore('#load-more-events', '#uc-event-right-panel-listing'); | EnableAutoLoadMore('#load-more-events', '#uc-event-right-panel-listing'); | ||
− | } | + | } else if (window.location.pathname.substring(0, 7) == '/groups') { |
− | |||
− | |||
EnableAutoLoadMore('#uc-more-group-search', '.category-box-wrapper'); | EnableAutoLoadMore('#uc-more-group-search', '.category-box-wrapper'); | ||
$('.club-navigation ul li').click(function() { | $('.club-navigation ul li').click(function() { | ||
Line 33: | Line 31: | ||
$('#uc-more-group-search').first().attr('data-loadmore', 0); | $('#uc-more-group-search').first().attr('data-loadmore', 0); | ||
}); | }); | ||
− | } | + | } else if (window.location.pathname.substring(0, 9) == '/articles' && window.location.pathname.length <= 10) { |
− | |||
− | |||
EnableAutoLoadMore('#load_more_article', '.uc-articles-listing'); | EnableAutoLoadMore('#load_more_article', '.uc-articles-listing'); | ||
− | } | + | } else if (window.location.pathname.substring(0, 16) == '/thestudentvoice' && window.location.pathname.length <= 17) { |
− | |||
− | |||
EnableAutoLoadMore('#load_more_sv', '.uc-sv-left-panel-wrapper'); | EnableAutoLoadMore('#load_more_sv', '.uc-sv-left-panel-wrapper'); | ||
$('#uc-sv-navigation li a').click(function() { | $('#uc-sv-navigation li a').click(function() { |
Revision as of 16:29, 15 December 2016
There are many pages on the platform that limit the content shown, and have a 'load more' button at the bottom which loads the next page when clicked.
The following code snippet enables automatic loading of the content as visitors scroll down the page, similar to how Facebook and Twitter do, improving the user experience as users can just scroll down without having to keep clicking 'load more'.
To snippet should be copied into Global Javascript.
function EnableAutoLoadMore(buttonElement, contentElement) { $(window).bind('scroll', function() { if (typeof $(buttonElement).first().attr('data-loadmore') === typeof undefined || $(buttonElement).first().attr('data-loadmore') == false) { $(buttonElement).first().attr('data-loadmore', 0); } if ($(buttonElement + ':visible').length > 0) { if (($(window).height() + $(document).scrollTop()) > ($(buttonElement).first().offset().top - 80) && $(contentElement).first().children().length > $(buttonElement).first().attr('data-loadmore')) { $(buttonElement).first().attr('data-loadmore', $(contentElement).first().children().length); $(buttonElement).click(); } } }); } $(function() { if (window.location.pathname.substring(0, 7) == '/events' && window.location.pathname.length <= 8) { EnableAutoLoadMore('#load-more-events', '#uc-event-right-panel-listing'); } else if (window.location.pathname.substring(0, 7) == '/groups') { EnableAutoLoadMore('#uc-more-group-search', '.category-box-wrapper'); $('.club-navigation ul li').click(function() { $('#uc-more-group-search').first().attr('data-loadmore', 0); }); $('.group-types-wrapper ul li').click(function() { $('#uc-more-group-search').first().attr('data-loadmore', 0); }); } else if (window.location.pathname.substring(0, 9) == '/articles' && window.location.pathname.length <= 10) { EnableAutoLoadMore('#load_more_article', '.uc-articles-listing'); } else if (window.location.pathname.substring(0, 16) == '/thestudentvoice' && window.location.pathname.length <= 17) { EnableAutoLoadMore('#load_more_sv', '.uc-sv-left-panel-wrapper'); $('#uc-sv-navigation li a').click(function() { $('#load_more_sv').first().attr('data-loadmore', 0); }); } });