Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: opacity

  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post

    opacity

    http://www.clagnut.com/sandbox/imagefades/

    Code:
    function setOpacity(obj, opacity) {
      opacity = (opacity == 100)?99.999:opacity;
      
      // IE/Win
      obj.style.filter = "alpha(opacity:"+opacity+")";
      
      // Safari<1.2, Konqueror
      obj.style.KHTMLOpacity = opacity/100;
      
      // Older Mozilla and Firefox
      obj.style.MozOpacity = opacity/100;
      
      // Safari 1.2, newer Firefox and Mozilla, CSS3
      obj.style.opacity = opacity/100;
    }
    function fadeIn(objId,opacity) {
      if (document.getElementById) {
        obj = document.getElementById(objId);
        if (opacity <= 100) {
          setOpacity(obj, opacity);
          opacity += 75; // the level of darkness (100 - high, 0 - low)
          window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
        }
      }
    }
    
    function initImage() {
      imageId = 'thephoto';
      image = document.getElementById(imageId);
      setOpacity(image, 0);
      image.style.visibility = 'visible';
      fadeIn(imageId,0);
    }
    
    
    window.onload = function() {initImage()}
    document.write("<style type='text/css'>#thephoto {visibility:hidden;} </style>");
    Can anyone see a way to speed up the change from my original image to the white image?

    The opacity?

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    not very clear to me... To change the speed you may increase the rate of substract and/or to decrease the rate of setTimeout function. Anyway, for the latest, for almost all the browsers the rate under 70 miliseconds will have no effect.

    Anyway I guess that you should also include a clearTimeout() function when the opacity turns to 0, to avoid unecessary math underground calculation
    Last edited by Kor; 04-14-2005 at 04:04 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •