Controlling Loop speed for animation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • M Katz

    Controlling Loop speed for animation

    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('wid thup()',0);
    }
    }

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


  • Lasse Reichstein Nielsen

    #2
    Re: Controlling Loop speed for animation

    "M Katz" <compukat@video tron.ca> writes:
    [color=blue]
    > 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;[/color]

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

    Try changing this to:
    width.firstChil d.nodeValue = image.width;
    It is known to be faster and even more widely supported.
    [color=blue]
    > if(x==1) {
    > setTimeout('wid thup()',0);[/color]

    Try changing this to
    setTimeout(widt hup,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.firstChil d.nodeValue = ++(image.width) ;
    }

    var cid;
    function startIt() {
    cid = setInterval(wid thup,50);
    }
    function stopIt() {
    clearInterval(c id);
    }
    ---


    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • M Katz

      #3
      Re: Controlling Loop speed for animation


      "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
      news:wuemkl3e.f sf@hotpop.com.. .[color=blue]
      > "M Katz" <compukat@video tron.ca> writes:
      >[color=green]
      > > I'm using the following to allow dynamic resixing of an image (when the[/color][/color]
      usre[color=blue][color=green]
      > > presses down on a button):
      > >
      > > function widthup() {
      > > image.width = image.width + 1;
      > > width.innerText = image.width;[/color]
      >
      > I assume that "image" and "width" are variables declared somewhere else.
      >
      > Try changing this to:
      > width.firstChil d.nodeValue = image.width;
      > It is known to be faster and even more widely supported.
      >[color=green]
      > > if(x==1) {
      > > setTimeout('wid thup()',0);[/color]
      >
      > Try changing this to
      > setTimeout(widt hup,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.firstChil d.nodeValue = ++(image.width) ;
      > }
      >
      > var cid;
      > function startIt() {
      > cid = setInterval(wid thup,50);
      > }
      > function stopIt() {
      > clearInterval(c id);
      > }[/color]


      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('wid thup()',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!


      Comment

      • Evertjan.

        #4
        Re: Controlling Loop speed for animation

        M Katz wrote on 14 jul 2003 in comp.lang.javas cript:
        [color=blue]
        > 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('wid thup()',0);
        > }
        >}
        >
        > even when the 'setTimout' is at zero it goes pretty slowly. Any way to
        > have something faster?
        >[/color]

        image.width = image.width + 2;

        or more consize:

        image.width += 2;



        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        Working...