Web Analytics Made Easy -
StatCounter My js needs a brake - CodingForum

Announcement

Collapse
No announcement yet.

My js needs a brake

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

  • My js needs a brake

    I have a function and i want to do something like this

    alert('hey')

    then i want a 10 sec brake and do this:

    alert('hey again')

    however THE BRAKE MAY NOT BE A TIMEOUT

    thanks for any help
    http://www.bluephoenix.uni.cc/

  • #2
    function test()
    {
    alert('hey');
    breaktime=10000;
    Time=new Date();

    while((new Date()-Time)<breaktime){}

    alert('hey again');
    }



    Note I wouldn't use it , it more or less locks ur browser

    Comment


    • #3
      yes, it crahsed my broswer several times.... No i dont think i can use that but thanks alot

      any other ideas?
      http://www.bluephoenix.uni.cc/

      Comment


      • #4
        Maybe this can help you help me

        Code:
        this.fadeUp=function(){
        		if(this.i<1 && UD==1){
        			this.i+=0.01;
        
        		document.getElementById(this.imgId).style.MozOpacity=this.i;
        			setTimeout(this.fadeUp, 10);
        			}}
        ofcourse the setTimeout doesnt work like that so i tried this

        setTimeout('this.fadeUp()', 10) and it tried to call the function this.fadeUp but now it doesnt read the this as a variable and replaces for Example Smiley, no it just reads it as the string this which is ofcourse not defined.

        so all i need is to repeat that function after 10 msec

        hopefully that helped you help me

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

        Comment


        • #5
          You said in your original post that you can't use a timeout

          Comment


          • #6
            exactly that is why i need a different function for that the does the same thing
            http://www.bluephoenix.uni.cc/

            Comment


            • #7
              whats wrong with settimeout?

              it work well.

              eksample 3rd pic.
              http://www.the-hive.dk/~donp/Library/Test_advImage.html

              Comment


              • #8
                whats wrong with setTimout?

                here it doesnt support my object method this.fadeUp()

                see:

                setTimeout('this.fadeUp()', 10)


                see what i mean?

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

                Comment


                • #9
                  when you use setTimeout you need to remember it calls the function from a global point not from within an object.

                  setTimeout('OBJECTNAME.fadeUp()', 10)

                  Comment


                  • #10
                    so how could i fix this?
                    http://www.bluephoenix.uni.cc/

                    Comment


                    • #11
                      Try:

                      Code:
                      [b]var me=this;[/b]
                      this.fadeUp=function(){
                          if(this.i<1 && UD==1){
                          	this.i+=0.01;
                         
                              document.getElementById(this.imgId).style.MozOpacity=this.i;
                              setTimeout([b]me[/b].fadeUp, 10);
                          }
                      }
                      Glenn
                      vBulletin Mods That Rock!

                      Comment


                      • #12
                        thanks alot....

                        Code:
                        <html>
                        <head>
                        <style>
                        .img{
                        	-moz-opacity: 0.3;
                        	}
                        </style>
                        <script>
                        var UD=1;
                        function fade(){
                        	this.stopFU=function(){UD=0}
                        	this.stopFD=function(){UD=1}
                        	this.imgId='img1';
                        	this.i=.3;
                        	var me=this;
                        	
                        	this.fadeUp=function(){
                        		if(me.i<1 && UD==1){
                        			me.i+=0.01;
                        			document.getElementById(me.imgId).style.MozOpacity=me.i;
                        			setTimeout(me.fadeUp, 10)
                        			}
                        		else{me.stopFU}
                        		}
                        		
                        	this.fadeDown=function(){
                        		if(me.i>=.3 && UD==0){
                        			me.i-=0.01;
                        			document.getElementById(me.imgId).style.MozOpacity=me.i;
                        			setTimeout(me.fadeDown, 10);			
                        			}
                        		else{UD=1}
                        		}
                        	}
                        
                        var Smiley1=new fade();
                        Smiley1.imgId='img1';
                        var Smiley2=new fade();
                        Smiley2.imgId='img2';
                        
                        </script>
                        </head>
                        <body>
                        <img src="smiley.gif" onmouseover="Smiley1.stopFD();Smiley1.fadeUp()" onmouseout="Smiley1.stopFU();Smiley1.fadeDown()" id="img1" class="img">
                        <img src="smiley.gif" onmouseover="Smiley2.stopFD();Smiley2.fadeUp()" onmouseout="Smiley2.stopFU();Smiley2.fadeDown()" id="img2" class="img">
                        </body>
                        </html>
                        please take a look at this code. If you run this code it fades up and down perfectly thanks to glenn, but here is a mjor flaw:

                        Let the first image fade Up all the way and then remove ur mouse from it u will notice that it does not fade down.
                        Now mouse over it again and then remove ur mouse form the already fadedUp image, now it will fade down

                        it only fades down the second time.... why?

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

                        Comment

                        Working...
                        X