SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    First tests with a fade script.

    Hi all.
    PHP Code:
    function setOpacity(el,value) {
        var 
    v= +value;
        
    el.style.opacity v/10;
        
    el.style.filter 'alpha(opacity=' v*10 ')';
    }
    function 
    fade(){
        var 
    opt10;
        var 
    stop3;
        var 
    selfthis;
        function 
    f(){    
            if(
    opt>stop){
                
    opt--;
                
    setOpacity(self,opt);
            }
            else if(
    opt==stop){
                
    window.clearTimeout(timeoutID);
                
    opt=stop;
            }
            var 
    timeoutIDwindow.setTimeout(f100);
        }
        
    f();
    }
    window.onload= function(){
        var 
    _imgdocument.getElementsByTagName('img')[0];
        
    _img.onclick=fade;

    I know there is a better way to do that

    Can you help me, please ?

    Bye.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This is my stab at it. Not particularly different, but a small improvement I think.
    Code Javascript:
    function setOpacity(el,value) {
        el.style.opacity = value/10;
        el.style.mozOpacity = value/10;
        el.style.filter = 'alpha(opacity=' + value*10 + ')';
    }
     
    function fade(){
        var opt= 10;
        var stop= 3;
        var timeoutID = window.setInterval(f, 100);
        function f(){    
            if(opt>stop){
                opt--;
                setOpacity(this,opt);
            }
            else {
                window.clearTimeout(timeoutID);
            }
        }
    }
     
    window.onload= function(){
        var _img= document.getElementsByTagName('img')[0];
        _img.onclick=fade;
    }

  3. #3
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think a typo
    PHP Code:
    function setOpacity(el,value) {
        
    el.style.opacity value/10;
        
    el.style.mozOpacity value/10;
        
    el.style.filter 'alpha(opacity=' value*10 ')';
    }
    function 
    fade(){
        var 
    opt10;
        var 
    stop3;
        var 
    timeoutID window.setInterval(f100);
        var 
    selfthis;
        function 
    f(){    
            if(
    opt>stop){
                
    opt--;
                
    setOpacity(self,opt);
            }
            else {
                
    window.clearTimeout(timeoutID);
            }
        }
    }
     
    window.onload= function(){
        var 
    _imgdocument.getElementsByTagName('img')[0];
        
    _img.onclick=fade;

    this isn't in the scope of f().

    I like very much
    var timeoutID = window.setInterval(f, 100); out of f()

    Thanks a lot buddy.

    Bye.

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ah yes, well caught.


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
  •