SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,761
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OnMouseOut: Countdown to Javascript Function

    I have a javascript function that is 'hide()'

    When a person does onmouseover on certain images, I want a countdown (lets say 6 seconds) to reset and stop. OnMouseOut, I want the javascript to countdown six seconds and then run the 'hide()' function.

    How is this possible?

    Thanks
    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,761
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I got this working, but the countdown is not resetting when I mouseover another image. It continues to countdown and do the 'hide()' function once the countdown has begun.

    Code:
    <script language="javascript1.2">
    var secs;
    var count;
    
    function Start() {
    secs="6"; 
    setTimeout("countDown()",1000);
    }
    
    function Stop() {
    if (count) { clearTimeout(count); }
    }
    function countDown() {
    if(secs==0) { return; }
    secs--;
    if(secs<1) { hide(); return; }
    count=setTimeout("countDown()",1000);
    }
    </script>
    How can I reset the timer onmouseover? As part of the Stop() function, reset the time.

    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  3. #3
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.
    Try this without global variable:

    PHP Code:
    function hide(){
        
    alert("Hi");
    }
    function 
    start(){
        var 
    secs6;
        var 
    timeoutID window.setInterval(countDown1000);
        function 
    countDown(){    
            if(
    secs>0){
                
    secs--;
            }
            else {
                
    stop(); 
                
    hide();
            }
        }
        function 
    stop(){
            
    secs6;
            
    window.clearTimeout(timeoutID);
        }
    }
    start(); 
    Bye.
    Last edited by whisher; Jun 17, 2008 at 15:06.

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,761
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help, but i had some issues with that. After simplifying it, I came up with this:

    Code:
    <script>
    function Start() {
    st = setInterval("hide()",5000); 
    return false;
    
    }
    function Stop() {
    clearInterval(st);
    return false;
    }
    Start();
    </script>
    Simeple and works

    Thanks
    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.


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
  •