[英]JavaScript: How to prevent loadscrollPagination function to be loaded multiple times
I'm working on a project using the jquery-scroll-pagination plugin to dynamic load additional content when scrolling: https://github.com/andferminiano/jquery-scroll-pagination 我正在使用jquery-scroll-pagination插件在滚动时动态加载其他内容的项目上: https : //github.com/andferminiano/jquery-scroll-pagination
The idea is to facilitate the user with different views. 这个想法是为了方便用户使用不同的视图。 This is currently being done by using the jquery load event in a way that when an user clicks a button the content will be loaded.
当前,这是通过使用jquery load事件来完成的,即当用户单击按钮时,将加载内容。
The problem I'm facing is that the "scrollPagination" functions remains in memory and being active on #content. 我面临的问题是“ scrollPagination”函数保留在内存中,并且在#content上处于活动状态。 If an user clicks away the view and switches back, the scrollPagination for #content is loaded a second time.
如果用户单击该视图并切换回去,则会再次加载#content的scrollPagination。 All calls are executed twice then.
然后,所有调用执行两次。
Is there a way to prevent the scrollPagination function being active multiple times? 有没有一种方法可以防止scrollPagination函数多次激活?
function loadscrollPagination() {
setTimeout(function() {
$('#content').scrollPagination({
nop: 10, // The number of posts per scroll to be loaded
offset: 0, // Initial offset, begins at 0 in this case
error: 'No More Posts!', // When the user reaches the end this is the message that is
delay: 500, // When you scroll down the posts will load after a delayed amount of time.
scroll: true // The main bit, if set to false posts will not load as the user scrolls.
});
}, 100);
}
$("div.detail").click(function() {
$('section').load('detailed-view.php', function() {
loadscrollPagination();
});
});
Perhaps jQuery.one()
will do the trick: 也许
jQuery.one()
可以解决问题:
#('section').one('load', 'detailed-view.php', function() {...})
See here for more info: http://api.jquery.com/one/ 请参阅此处以获取更多信息: http : //api.jquery.com/one/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.