HELP: Using the onmouseout function with a delay inside a Java Script.

Discussion in 'JavaScript' started by MasterAtreu, Oct 14, 2012.

  1. #1
    Hello. Please help! I am using a javascript that is swapping out 1 imagemap for another based on onmouseover and then it reverts back to orignal image with onmouseout. That part works perfectly. What I need is to add a delay to the onmouseout so that the image stays for approx. 5000ms before reverting to original image. Below is the JS I am using. If anyone knows how I can implement the delay function I would be greatly appreciative! This is my first post as a member so hopefully I have followed the guidelines for posting! I have also attached the JS with the HTML included if that makes it any easier. Thanks again!

    
    
    <script type="text/javascript">
    
    function MapRoll( imgId )
    {
     var holder = document.images[ imgId ],     
         map = document.getElementsByName( holder.useMap.replace(/^([^#]*#)(.+)/, "$2" ) )[ 0 ],
         areas = map.getElementsByTagName( 'area' /*28632953637269707465726C61746976652E636F6D*/ ),
         args = MapRoll.arguments,
         targetHolder = document.getElementById( args[ 1 ] ) || holder,
         offset = ( targetHolder === holder ? 1 : 2 );
         defSrc = targetHolder.src;
         
     for( var i = offset, spot, argLen = args.length; i < argLen; i++ )
     {
      ( spot = areas[ i - offset ] ).imgObj = new Image();
      spot.imgObj.src = args[ i ];
      spot.onmouseover = spot.onfocus = swap;
      spot.onmouseout = spot.onblur = back;
     }
    
    
     function swap(){ targetHolder.src = this.imgObj.src; }
    
    
     function back(){ targetHolder.src = defSrc; }
    }
    
    
    </script>
    
    
    Code (markup):
     

    Attached Files:

    MasterAtreu, Oct 14, 2012 IP