473,765 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer in firefox, opera, et al.

Hello,
I'm using the setTimeout function to perform some animation. The timeout
I'm using is 30ms, which works well in IE and produces smooth animation.
However, in other, more standards compliant browsers, it plays back much
slower. It seems like this happens to the same degree on all of these
browsers, and if I increase or decrease the timeout by a little bit it
doesn't have any effect. This leads me to believe that there is some
minimum timeout for this function in the standards (are there any
standards?) but I can't find any info on this.

If I increase the timeout and increase the "jump" of the animation, it works
at the correct rate but looks like crap. Any way to get the other browsers
to give me 30ms precision?

Thanks,
-Jeremy
Jul 23 '05 #1
2 1603
"Jeremy" <je*****@uci.ed u> writes:
This leads me to believe that there is some minimum timeout for this
function in the standards (are there any standards?)
There are no standards. There is a, browser and OS dependent, minimum
delay, the timer granularity. However, in IE 6, Moz FF and Opera 7,
that seems to be 10ms (as witnessed by this program:)
---
var t1;
var times = [];
var n=0;
function timer() {
var t2 = new Date();
times.push(t2-t1);
t1=t2;
if (--n>0) {
setTimeout(time r,1);
}
}

function report() {
alert(times);
}
setTimeout(repo rt,1000);
n=5;
t1=new Date();
setTimeout(time r,1);
---

If the delay between rounds is more than that, maybe it is the time it
takes to update the animation that counts against you. If you call the
setTimeout again at the end of each step, you will be delayed by the
time it takes to do the step.
If I increase the timeout and increase the "jump" of the animation, it works
at the correct rate but looks like crap. Any way to get the other browsers
to give me 30ms precision?


I would use setInterval(ste p,30) and hope the steps take less than 30
ms. It won't be exact, but it should be close enough.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
JRS: In article <lL1gc.9178$yD1 .28188@attbi_s5 4>, seen in
news:comp.lang. javascript, Jeremy <je*****@uci.ed u> posted at Sat, 17
Apr 2004 03:45:21 :
I'm using the setTimeout function to perform some animation. The timeout
I'm using is 30ms, which works well in IE and produces smooth animation.
However, in other, more standards compliant browsers, it plays back much
slower. It seems like this happens to the same degree on all of these
browsers, and if I increase or decrease the timeout by a little bit it
doesn't have any effect. This leads me to believe that there is some
minimum timeout for this function in the standards (are there any
standards?) but I can't find any info on this.

If I increase the timeout and increase the "jump" of the animation, it works
at the correct rate but looks like crap. Any way to get the other browsers
to give me 30ms precision?


You could have consulted the newsgroup FAQ on the subject of time; see
sig below.

The resolution of the date object itself is by definition one
millisecond; but the values of new Date() increase in steps of 10 ms for
WinNT+ systems or 55 ms for Win98x systems (and possibly other values
for other systems).

<URL:http://www.merlyn.demo n.co.uk/js-dates.htm#OV> refers; and will
show the resolution of the browser being used.

The same timing mechanism is (extremely likely to be) used for the
setTimeout function, and for setInterval too.

I expect the resolution to be an OS property, otherwise independent of
browser version.
For use on a 55 ms system, you could in principle write a time-wasting
loop, see how many times it could be executed between successive 55 ms
timeouts, similarly time your display routine, then use that information
to attempt a hand-crafted 27.5 ms interval between a timed display call
and a fill-in one. It seems a dubious approach, but there may be no
better.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr times, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2303
by: Boris | last post by:
Please open http://www.highscore.de/opera/floatleft.html in Opera 7.54 and Firefox 1.0 Preview. Who is right? In my humble opinion Opera 7.54 is right: According to CSS 2.1 a "floating box must be placed as high as possible" (see http://www.w3.org/TR/CSS21/visuren.html#float-position rule #8). Do you agree? BTW, Internet Explorer 6 behaves like Opera 7.54.
2
7976
by: Sharon | last post by:
Can I use request.servervariables("HTTP_USER_AGENT") to determine if the user has Firefox or Internet Explorer? Is the return string differentiated enough? Thanks for any input.
15
2198
by: 50295 | last post by:
Hi everyone, This one is better experienced than explained, so I'm including a code sample below. Please and save (as an html file) and view with NN or Firefox (or maybe even Mozilla), and then view. When loaded: (1.) Place the mouse over "Top Menu" item. (The menu opens) (2.) Move to any of the sub-menu items. (3.) Click on the left or right (but NOT on the text) of the current
9
3308
by: VK | last post by:
if ((window)&&(window.netscape)&&(window.netscape.security)) { // OK, this is Gecko/Firefox or someone mimicing it so well // that there is no way to catch it on the act. } But I need Firefox *1.5 or higher* or another (but sure) way to know that this browser has native SVG support. Here I'm stock. It seems there is window.navigator.productSub and on my Firefox 1.5 it's 20051111
11
1926
by: Hymer | last post by:
Hello, I have a small table that works fine in IE6 but does not render at all in Opera or Firefox. Can anyone see what might be needed to get this to work in all three browsers? The code is below.
2
5702
by: André Wagner | last post by:
I'm trying to get all the "divs" that have a given NAME using getElementsByName(). For example, the following code: <html> <head> <script type="text/javascript"> function on_load() { var pages = document.getElementsByName("name");
5
3965
by: VK | last post by:
On the demo at <http://www.geocities.com/schools_ring/tmp/demo01/index.xml> the table caption has 1px(?) indentation from the left in Firefox 1.5 and I'm running out of ideas how to kill it - if it's possible at all. (Opera 9 shows a bigger indentation (2px?) but from the right side, but this fun is for later :-) IE displays the expected (at least by me) layout. The relevant HTML block in the transformer...
6
1950
by: raknin | last post by:
I am creating a dynamic list on the server using php file,when I run the PHP script in all 4 browsers (IE 6, Firefox 2, opera and safari 3) every think go Ok and the list is created. but when I call the php script from the browser using Ajax, the list is created fine in IE and Opera but on Firefox and safari I got the following error: "Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in...
29
8174
by: canabatz | last post by:
Hello , i got this code that works great , now i want to have it refresh every 4 seconds , where can i put the timer to do that? i realy need help!! thanx!! <script type="text/javascript"> //Global vars to hold connection to web pages var request;
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.