我试图调用一个函数,它将在结束时再次调用该函数,因此它将无限期地重复。
function foo2 () {
setTimeout(function(){
jQuery('#bloc2').height(jQuery('#zonetexteposition').height());
jQuery('#bloc2-vertical').height(jQuery('#zonetexteposition').height());
jQuery('#bloc2-horizontal').height(jQuery('#zonetexteposition').height());
}, 1000);
}函数已经在页脚中调用了,但是对于特定的页面,#zonetexteposition高度经常会自动更改,所以我希望页面能够调整大小。
发布于 2015-07-28 18:33:42
如果要重复调用函数,则需要setInterval,而不是setTimeout。
在延迟之后,setTimeout只调用一次回调。setInterval反复调用其回调,直到clearInterval取消为止。
发布于 2015-07-28 18:37:24
这将与您的代码一起工作:
function foo2 () {
setTimeout(function(){
foo2();
jQuery('#bloc2').height(jQuery('#zonetexteposition').height());
jQuery('#bloc2-vertical').height(jQuery('#zonetexteposition').height());
jQuery('#bloc2-horizontal').height(jQuery('#zonetexteposition').height());
}, 1000);
}
foo2();但是最好使用setInterval而不是setTimeout。
setInterval(function(){
jQuery('#bloc2').height(jQuery('#zonetexteposition').height());
jQuery('#bloc2-vertical').height(jQuery('#zonetexteposition').height());
jQuery('#bloc2-horizontal').height(jQuery('#zonetexteposition').height());
}, 1000);关于在特定页面中不工作的问题,您能给出更多的细节/代码吗?
https://stackoverflow.com/questions/31684352
复制相似问题