Results 1 to 3 of 3

Thread: Jasoop setTimeout

  1. #1
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default Jasoop setTimeout

    Okay: you may have heard I've been working on a fairly buggy 'toolbox'. One little problem: I tried making a custom setTimeout function. There isn't an error, but I do have one concern. How could I make it NOT pause when the user sets the timeout? I have a do..while loop. I want the thing to do what I want without pausing the screen and the user. Here is the code:

    Code:
    /********** - IMPORTANT LABEL - **********/
    /* Title: Jasoop Toolbox                 */
    /* Name: jasoop.js                       */
    /* Author: 2008 Arthur C. Watkins        */
    /* Notice: This label is to stay intact  */
    /* for usage of this document.           */
    /********** - IMPORTANT LABEL - **********/
    
    // Start Jasoop Toolbox
    
    var _ = function (el) {
    if(document.getElementById())	return document.getElementById(el);
    else if(document.all)		return document.all[el];
    else if(document.layers) 	return document.layers[el];
    else return false;
    };
    
    var Concatenate = function () {
    var string = '';
    for(x=0;x<arguments.length;x++) {
    string=string+arguments[x];
    }
    return string;
    };
    
    var clock = Date.now || function(){
    return new Date().getTime();
    };
    
    var wait = function (statement,delay) {
    var start,end,loop;
    start = clock();
    end = (start+delay);
    do {                     // my problem
    loop = clock();       // my problem
    } while (loop<end); // my problem
    setTimeout(statement,0);
    };
    
    var Animation = function (el) {
    this.element = el;
    this.x = [];
    this.y = [];
    this.delay = [];
    this.ac = 0;
    this.lc = 0;
    this.pause = false;
    this.autodelete = false;
    this.loop = false;
    };
    
    Animation.prototype.moveTo = function (x,y) {
      _(this.element).style.position="absolute";
      _(this.element).style.left=(x+"px");
      _(this.element).style.top=(y+"px");
    };
    
    Animation.prototype.start = function () {
      var animation = this;
      if(!this.pause)
      {
        if(this.ac<this.lc)
        {
          this.moveTo(this.x[this.ac],this.y[this.ac]);
          this.ac++;
          setTimeout(function(){animation.start()},this.delay[this.ac]);
        }
        else if(this.ac>=this.lc)
        {
          (this.autodelete) ? this.reset() : this.ac=0;
          (this.loop && !this.autodelete) ? this.start() : "";
        }
      }
      else if(this.pause)
      {
        this.pause = !this.pause;
      }
    };
    
    
    Animation.prototype.stop = function () {
      this.pause = true;
    };
    
    Animation.prototype.compute = function (l,t,d) {
      this.x[this.lc]=l;
      this.y[this.lc]=t;
      this.delay[this.lc]=d;
      this.lc++;
    };
    
    
    Animation.prototype.reset = function() {
      for(i=0;i<=this.ac;i++)
      {
          this.x[i]=0;
          this.y[i]=0;
          this.delay[i]=0;
      }
      this.lc=0;
      this.ac=0;
    };
    
    // End Jasoop Toolbox
    
    /********** - IMPORTANT LABEL - **********/
    /* Title: Jasoop Toolbox                 */
    /* Name: jasoop.js                       */
    /* Author: 2008 Arthur C. Watkins        */
    /* Notice: This label is to stay intact  */
    /* for usage of this document.           */
    /********** - IMPORTANT LABEL - **********/
    Please help.

    -magicyte
    Last edited by magicyte; 10-22-2008 at 10:07 PM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I don't get what you mean, do you have an example page?
    Jeremy | jfein.net

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You'd have to use setTimeout(). Do not use eval().

    Additionally, I see that most of the issues I pointed out in your other thread are still there, some weeks later.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •