admin管理员组文章数量:1022719
Pretty much, my question is simple, and I did search for a similar question before posting this. I would like to know how to make Javascript code repeatedly execute while the page is open, rather than the code running once and being done or only responding to event handlers. I pretty much want the Javascript equivilant of:
$(document).ready(function() {
});
But I do not want to use Jquery because it is less efficient. I want to check an === condition every single frame.
Pretty much, my question is simple, and I did search for a similar question before posting this. I would like to know how to make Javascript code repeatedly execute while the page is open, rather than the code running once and being done or only responding to event handlers. I pretty much want the Javascript equivilant of:
$(document).ready(function() {
});
But I do not want to use Jquery because it is less efficient. I want to check an === condition every single frame.
Share Improve this question asked Oct 9, 2014 at 2:38 turkey3turkey3 352 silver badges8 bronze badges 4- look up setInterval() – jollarvia Commented Oct 9, 2014 at 2:39
- Thanks! Can you give me a quick code example of how to actually incorporate it to my desired results? – turkey3 Commented Oct 9, 2014 at 2:41
-
1
rather than the code running once and being done or only responding to event handlers This is what you should (must) do. If your code is running non-stop, then the page would freeze. If you use a
setInterval
loop, then it is not even an efficient approach to any problem. I don't know what you are doing here, but every time you try to execute the same code repeatedly, it will not be efficient (that says jQuery is often more efficient then the code you write.) – Derek 朕會功夫 Commented Oct 9, 2014 at 2:56 - Can you run the === on frame load or a few ms after load using setTimeout(function(){}, 20);? Is there a frame load hook? – K'shin Gendron Commented Oct 9, 2014 at 4:11
3 Answers
Reset to default 3Use SetInterval .. inside a window.onload function
window.onload = function() {
function test() {
alert("test");
}
setInterval(test, time_miliseconds);
}
setInterval(function(){
var blah = whatever;
if (done){
clearInterval();
}
},time_in_milliseconds);
loop keeps looping per your milliseconds argument. If you want a loop thinner than a millisecond or as hard as the puter can do it then just a regular while(true){} will suffice.
requestAnimationFrame(callback)
docs
Pretty much, my question is simple, and I did search for a similar question before posting this. I would like to know how to make Javascript code repeatedly execute while the page is open, rather than the code running once and being done or only responding to event handlers. I pretty much want the Javascript equivilant of:
$(document).ready(function() {
});
But I do not want to use Jquery because it is less efficient. I want to check an === condition every single frame.
Pretty much, my question is simple, and I did search for a similar question before posting this. I would like to know how to make Javascript code repeatedly execute while the page is open, rather than the code running once and being done or only responding to event handlers. I pretty much want the Javascript equivilant of:
$(document).ready(function() {
});
But I do not want to use Jquery because it is less efficient. I want to check an === condition every single frame.
Share Improve this question asked Oct 9, 2014 at 2:38 turkey3turkey3 352 silver badges8 bronze badges 4- look up setInterval() – jollarvia Commented Oct 9, 2014 at 2:39
- Thanks! Can you give me a quick code example of how to actually incorporate it to my desired results? – turkey3 Commented Oct 9, 2014 at 2:41
-
1
rather than the code running once and being done or only responding to event handlers This is what you should (must) do. If your code is running non-stop, then the page would freeze. If you use a
setInterval
loop, then it is not even an efficient approach to any problem. I don't know what you are doing here, but every time you try to execute the same code repeatedly, it will not be efficient (that says jQuery is often more efficient then the code you write.) – Derek 朕會功夫 Commented Oct 9, 2014 at 2:56 - Can you run the === on frame load or a few ms after load using setTimeout(function(){}, 20);? Is there a frame load hook? – K'shin Gendron Commented Oct 9, 2014 at 4:11
3 Answers
Reset to default 3Use SetInterval .. inside a window.onload function
window.onload = function() {
function test() {
alert("test");
}
setInterval(test, time_miliseconds);
}
setInterval(function(){
var blah = whatever;
if (done){
clearInterval();
}
},time_in_milliseconds);
loop keeps looping per your milliseconds argument. If you want a loop thinner than a millisecond or as hard as the puter can do it then just a regular while(true){} will suffice.
requestAnimationFrame(callback)
docs
本文标签: Check Javascript Condition Every FrameStack Overflow
版权声明:本文标题:Check Javascript Condition Every Frame - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745525742a2154515.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论