Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 2 of 2
  1. #1
    Join Date
    May 2006
    Location
    Warwickshire
    Posts
    824
    Tokens
    0

    Default Need to cut down some code [+rep]

    Hey, I'm trying to get an image to fade in on mouseover and then fadeout when the mouse comes off it. I'm totally useless with this code, so can anyone cut it down as much as possible for me? It's got loads of junk code because I took it off another site...

    Don't ask me why I used that image lol.
    Oh and it's called mona, don't ask why either. lol. Thanks.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Cross Browser Image Fader - Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    
    var faders=[];
    // Preset each image's initial opacity (0 to 100):
    // ex:  faders[x]=['image_id', initial_opacity];
    faders[0]=['mona', 50];
    faders[1]=['arch', 0];
    
    function fade(el, way, op, opinc, speed){
    if(!fade.prprt&&!fade.ie)
    return;
    var id=typeof el=='string'? el : el.id, el=typeof el=='object'? el : document.getElementById(el);
    clearTimeout(fade[id+'timer']);
    var op_obj=fade.ie6? el.filters[0] : el.style,
    waym=way=='in'? 1 : -1, speed=speed? speed*1 : 30, opinc=opinc&&opinc>=1? opinc*(fade.ie? 1 : .01) : opinc? opinc : fade.ie? 5 : .05,
    op=op&&fade.ie? op*1 : op&&op*1>=1? Math.min(op*.01, .99) : op? op : waym>0&&fade.ie? 100 : waym>0? .99 : 0;
    if(!fade.ie6&&!fade[id+'yet']){
    if(fade.prprt)
    op_obj[fade.prprt]=Math.min(fade.preset(id)*.01, .99);
    else if(fade.ie)
    op_obj.filter='alpha(opacity='+fade.preset(id)+')';
    fade[id+'yet']=true;
    }
    if(fade.prprt&&Math.abs(op*1-op_obj[fade.prprt]*1)<opinc)
    op_obj[fade.prprt]=op;
    else if(fade.prprt)
    op_obj[fade.prprt]=fade.ie6? op_obj[fade.prprt]*1 + opinc*waym : Math.min(op_obj[fade.prprt]*1 + opinc*waym, .99);
    else if (fade.ie&&Math.abs(op*1 - op_obj.filter.replace(/\D/g,'')*1)<opinc)
    op_obj.filter='alpha(opacity='+op+')';
    else if (fade.ie)
    op_obj.filter='alpha(opacity='+[op_obj.filter.replace(/\D/g,'')*1 + opinc*waym]+')';
    else
    return;
    if(op_obj[fade.prprt]&&op_obj[fade.prprt]*waym<op*waym||!fade.ie6&&fade.ie&&op_obj.filter.replace(/\D/g,'')*waym<op*waym)
    fade[id+'timer']=setTimeout(function(){fade(el, way, op, opinc, speed)}, speed);
    }
    if(document.documentElement&&document.documentElement.style){
    fade.d=document.documentElement, fade.t=function(o){return typeof fade.d.style[o]=='string'}; if(fade.d.filters)
    document.write('<span id="ie_test" style="filter:progid:DXImageTransform.Microsoft.alpha(opacity=0);position:absolute;top:-1000px;">p<\/span>');
    fade.ie=fade.d.filters&&ie_test.filters[0], fade.ie6=fade.ie&&typeof ie_test.filters[0].opacity=='number',
    fade.prprt=fade.t('opacity')||fade.ie6? 'opacity' : fade.t('MozOpacity')? 'MozOpacity' : fade.t('KhtmlOpacity')? 'KhtmlOpacity' : null;
    }
    fade.set=function(){
    var prop=fade.prprt=='opacity'? 'opacity' : fade.prprt=='MozOpacity'? '-moz-opacity' : '-khtml-opacity';
    document.write('\n<style type="text/css">\n')
    for (var i = 0; i < faders.length; i++)
    document.write('#'+faders[i][0]+' {\n'+
    (fade.ie? 'filter:progid:DXImageTransform.Microsoft.alpha(opacity='+faders[i][1]+')' : prop+':'+Math.min(faders[i][1]*.01, .99))+';\n}\n');
    document.write('<\/style>\n')
    }
    fade.preset=function(id){
    for (var i = 0; i < faders.length; i++)
    if (id==faders[i][0])
    return faders[i][1];
    return 0;
    }
    if(fade.prprt||fade.ie)
    fade.set();
    </script>
    </head>
    <body>
    <div id="fadebg1"><img id="mona"
    src="http://i279.photobucket.com/albums/kk137/HabboPhotoAlbum/Rincewind.png" onmouseover="fade(this, 'in');" onmouseout="fade(this, 'out',50);" alt="Monalisa Image" title="Mona"></div>
    <div id="frond"><img id="arch" src="frond2_a.png" alt="Frond Arches Image" title="" onmouseover="fade(this, 'in',100,2,50);"
    onmouseout="fade(this, 'out',0,2,50);"></div>
    
    </body>
    </html>
    Last edited by Holofoil; 17-10-2008 at 08:21 PM.
    Light thinks it travels faster than anything but it is wrong. No matter how fast light travels, it finds the darkness has always got there first, and is waiting for it. - Terry Pratchett

  2. #2
    Join Date
    Mar 2008
    Location
    UK. America sucks!
    Posts
    310
    Tokens
    0

    Default

    You need all the code there for it to work.

    if PHP is peanut butter...then...MySQL would be the jelly. Together they can make one heck of a good sandwich.

Posting Permissions

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