admin管理员组文章数量:1289623
Is possible refresh a function every x seconds or refresh it on single event?
I will explain:
I have a function that makes pagination on my website, inside every div that are "pages" I have some pictures where I have added LightBox.
Everything works nice on the first div (page) but when I change the page it doesnt' work anymore.
I tried to fix in this way:
$('.pagination a').click(function () {
initShadow();
});
In this way it work on the pageLoad and on the first page that I change, than it stop again.
So I need to fix this issue, everytime I change the "page" I would like it works fine.
Is possible to refresh a function every x second or to refresh it everytime I click on the pagination buttons?
Is possible refresh a function every x seconds or refresh it on single event?
I will explain:
I have a function that makes pagination on my website, inside every div that are "pages" I have some pictures where I have added LightBox.
Everything works nice on the first div (page) but when I change the page it doesnt' work anymore.
I tried to fix in this way:
$('.pagination a').click(function () {
initShadow();
});
In this way it work on the pageLoad and on the first page that I change, than it stop again.
So I need to fix this issue, everytime I change the "page" I would like it works fine.
Is possible to refresh a function every x second or to refresh it everytime I click on the pagination buttons?
Share Improve this question edited Aug 29, 2011 at 21:05 jondavidjohn 62.4k21 gold badges120 silver badges159 bronze badges asked Feb 4, 2011 at 23:13 Andrea TurriAndrea Turri 6,5007 gold badges39 silver badges64 bronze badges 6- Is there one pagination button, or you have one on every page? – aorcsik Commented Feb 4, 2011 at 23:25
- are these 'pages' being loaded in via ajax? or being built dynamically after the page has already loaded? – jondavidjohn Commented Feb 4, 2011 at 23:25
- is a pagination, alot of pages... in everypage I want shadowbox (or other plugIns) to work... – Andrea Turri Commented Feb 4, 2011 at 23:26
- @jondavidjohn is not loaded via Ajax, just simple jQuery/css – Andrea Turri Commented Feb 4, 2011 at 23:26
- can we see the pagination code? – jondavidjohn Commented Feb 4, 2011 at 23:28
2 Answers
Reset to default 6I believe setInterval()
is what you are looking for. If you want to take the timed route.
setInterval(functionToExecute, 1000);
//this would call 'functionToExecute' every 1000 milliseconds
Otherwise, I would remend using .live()
instead of .click()
just incase your pagination links are being removed and recreated by the plugin. Thought this might be the case when you said it worked 1 additional time after you added this click event.
example
$('.pagination a').live('click',function () {
initShadow();
});
You can use the .on()
method of jQuery.
$(document).on('click', '.pagination a', function () {
initShadow();
});
Hope this helps.
本文标签: javascriptRefresh a jQuery functionStack Overflow
版权声明:本文标题:javascript - Refresh a jQuery function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741393989a2376265.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论