Search code examples
javascriptcolorsbackgroundfadeonmouseclick

Javascript Color Fading Delay


I am using this Javascript Color Fading Script.

http://www.scriptiny.com/2008/05/javascript-color-fading-script/

I set it to activate through 5 different links to fade the color of a single background

For example: http://sandbox.scriptiny.com/fader/fader.html (Div Background Transition)


The problem is simple, I need to have a delay for the user in between color fading links.

(Ex. User would have to wait 3 seconds to change color again.)

Here is the Javascript color fade file: http://pastebin.com/pxWphT2h

Any ideas are GREATLY appreciated, thanks!


Solution

  • Use a timer in your HTML file to not allow the function of changing color to start.

    <script type="text/javascript">
    var isOK = true;
    function OK2Go() {
        if (isOK == true) {
            isOK = false;
            setTimeout('isOK = true', 3000);
            return true;
        } else {
           return false;                   
        }
    }
    </script>
    ...  
    
    <a href="javascript:if(OK2Go()) {colorFade('testdiv7','background','ffffff','e4cdcd',50,15);}">div one</a> 
    

    See a sample in http://jsfiddle.net/ZphLx/ that only changes a text.