Web Analytics Made Easy -
StatCounter Using setTimeOut - CodingForum

Announcement

Collapse
No announcement yet.

Using setTimeOut

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using setTimeOut

    to use setTimeout it has to be in this format

    setTimeout('functionName()', 222)

    to add a function parameter i do this:

    setTimeout('functionName("'+parameter+'")', 222)

    that works good but how do i add a functionName?

    thanks for any help

    P.S. if you dont get what im tring to say please ask for more info

    thanks a lot
    http://www.bluephoenix.uni.cc/

  • #2
    I'm not sure what you mean, but you might try using an anonymous function, instead of a string:

    setTimeout(function(){functionName(arg1, arg2);}, 1000); - courtesy of beetle
    Last edited by swmr; Feb 15, 2004, 01:32 AM.
    hmm... ?

    Comment


    • #3

      I just started using OOP and heres what im tring to do:

      setTimeout('Smiley.fadeUp("'+imgid+'")', 10);

      ofcourse thats not it...

      what i want to do in fact is that it sets the timeout for this.fadeUp
      but when i put qouts around 'this.fadeUp()' then it does read the "this" as the value of this, but just a string "this" which ofcourse has no properties. sooo how could i do this


      thanks for the help so far
      http://www.bluephoenix.uni.cc/

      Comment


      • #4
        Oh, I don't know... maybe try using an anonymous function instead of a string.
        hmm... ?

        Comment


        • #5
          If it was javascript I would say its this:
          Code:
          <script>
          <!--
          function code() { // Replace the word "code" with the name of the function you want
          // Your code goes here
          }
          setTimeout('code()',222)
          //-->
          </script>
          But you are tying it in OOP, so I can't help you (I don't even know what it stands for).

          Comment


          • #6
            the smily one should work or at least it does for me

            Comment


            • #7
              Well, you could do this a couple different ways. First way is simple, what swmr suggested:

              setTimeout( function() { Smiley.fadeUp( imgid ) }, 10);

              2nd would involve changing your Smiley object. Instead of passing the imgid into the fadeUp method as an argument, make a new member variable for imgid and set it ahead of time (with a setter function or not). What this will allow us to do is point directly at the fadeUp method, since we would no longer need to pass any arguments to it.

              Smiley.setImgId( imgid ); // setter method
              setTimeout( Smiley.fadeUp, 10 );

              Depending on the nature of your object, this may or may not work.
              My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
              “Minds are like parachutes. They don't work unless they are open”
              “Maturity is simply knowing when to not be immature”

              Comment


              • #8
                swmr: Here is why your function doesnt work

                if i do this setTimeout(function(){this.fadeup()} then this referse to the function set in the timeout and no longer to the actual object.'

                Beetle Now i tried it your way and it now sais that the timeout call is useless cause it is no string.... whats wrong?
                Code:
                var UD=1;
                var i=.3
                function fade(imgId){
                	this.stopFU=function(){UD=0}
                	this.stopFD=function(){UD=1}
                	this.ImgId=imgId;
                
                	this.fadeUp=function(){
                		if(i<1 && UD==1){
                			document.getElementById(this.ImgId).style.MozOpacity=i;
                			i+=0.01;
                			setTimeout(this.fadeUp, 10);
                			}
                		if(i>=1){UD=0}
                		}
                		
                	this.fadeDown=function(imgId){
                		if(i>.3 && UD==0){
                			document.getElementById(this.ImgId).style.MozOpacity=i;
                			i-=0.01;
                			setTimeout(this.fadeDown, 10);
                			}
                		if(i<=.3){UD=1}
                		}
                	}
                
                
                var Smiley1=new fade('img1');
                var Smiley2=new fade('img2');
                http://www.bluephoenix.uni.cc/

                Comment


                • #9
                  I can see that you're wanting to create a "fade object", but can't see what makes it object-like... looks more like an action.
                  Why not just use a simple function?

                  function fadeUpDown(image){
                  var fadeMe = document.getElementById(image.id);
                  if(whatever){
                  fadeMe.style.MozOpacity = someHowFading;
                  }
                  else{
                  fadeMe.style.MozOpacity = someHowResolving;
                  }
                  setTimeout(function(){fadeUpDown(image)}, 10);
                  }
                  ...
                  <image id="imgId" onSomething="fadeUpDown(this)">
                  hmm... ?

                  Comment


                  • #10
                    because that wont work as soon as i have more then one image

                    http://www.bluephoenix.uni.cc/

                    Comment


                    • #11
                      delay btw urls after submission

                      i would like to ask if anyone could help me making a code to visit urls in blank page and make a delay btw that urls and all these action must happen with one click

                      for example i want to have it like this when i click a button

                      it goes to url 1 with delay 10 sec then go to url with delay 20 sec then go to url 3 with delay 30 sec etc ........... all with just one click .

                      is this could happen can anybody help me plz

                      Comment

                      Working...
                      X