By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,380 Members | 1,736 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,380 IT Pros & Developers. It's quick & easy.

Controlling Loop speed for animation

P: n/a
Hi,

I'm using the following to allow dynamic resixing of an image (when the usre
presses down on a button):

function widthup() {
image.width = image.width + 1;
width.innerText = image.width;
if(x==1) {
setTimeout('widthup()',0);
}
}

even when the 'setTimout' is at zero it goes pretty slowly. Any way to have
something faster?
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"M Katz" <co******@videotron.ca> writes:
I'm using the following to allow dynamic resixing of an image (when the usre
presses down on a button):

function widthup() {
image.width = image.width + 1;
width.innerText = image.width;
I assume that "image" and "width" are variables declared somewhere else.

Try changing this to:
width.firstChild.nodeValue = image.width;
It is known to be faster and even more widely supported.
if(x==1) {
setTimeout('widthup()',0);


Try changing this to
setTimeout(widthup,50);
It should be a little faster to use the function than to use a string
that must be parsed.

Setting the time to zero is unreasonable. It probably doesn't matter,
but I prefer not to provoke the system.

You could save a little time by using setInterval. Then you don't need
to reset the timer every round.

With a little massage, you get:

---
function widthup() {
width.firstChild.nodeValue = ++(image.width);
}

var cid;
function startIt() {
cid = setInterval(widthup,50);
}
function stopIt() {
clearInterval(cid);
}
---
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:wu**********@hotpop.com...
"M Katz" <co******@videotron.ca> writes:
I'm using the following to allow dynamic resixing of an image (when the usre presses down on a button):

function widthup() {
image.width = image.width + 1;
width.innerText = image.width;


I assume that "image" and "width" are variables declared somewhere else.

Try changing this to:
width.firstChild.nodeValue = image.width;
It is known to be faster and even more widely supported.
if(x==1) {
setTimeout('widthup()',0);


Try changing this to
setTimeout(widthup,50);
It should be a little faster to use the function than to use a string
that must be parsed.

Setting the time to zero is unreasonable. It probably doesn't matter,
but I prefer not to provoke the system.

You could save a little time by using setInterval. Then you don't need
to reset the timer every round.

With a little massage, you get:

---
function widthup() {
width.firstChild.nodeValue = ++(image.width);
}

var cid;
function startIt() {
cid = setInterval(widthup,50);
}
function stopIt() {
clearInterval(cid);
}

Hi and thanks! I actually solved it as follows:

step = 1;

function widthup() {
image.width = image.width + step;
width.innerText = image.width;
if(x==1) {
step++;
setTimeout('widthup()',0);
}
}

The idea is that as people press on the button longer the resizing speeds
up. Effectively, the amount of change start at 1 and increases by 1 at each
loop. When the button is released it resets "step" to 1. But I will try your
way also!
Jul 20 '05 #3

P: n/a
M Katz wrote on 14 jul 2003 in comp.lang.javascript:
I'm using the following to allow dynamic resixing of an image (when
the usre presses down on a button):

function widthup() {
image.width = image.width + 1;
width.innerText = image.width;
if(x==1) {
setTimeout('widthup()',0);
}
}

even when the 'setTimout' is at zero it goes pretty slowly. Any way to
have something faster?


image.width = image.width + 2;

or more consize:

image.width += 2;

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.