Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>What's wrong with this fadein?

What's wrong with this fadein?

kippie
01-08-2006, 10:54 AM
In the HTML below I want a div containing a text and an image to fade in after a preset time (in this case 2 seconds). The fadingin works but a little bit later there comes an error. What do I do wrong?

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive 4">
<title>Welcome to Adobe GoLive 4</title>


<script language="JavaScript"><!--

var isNS = document.layers?true:false;
var isIE = document.all?true:false;
var isDOM = document.getElementById?true:false;

function show(id)
{
if (isNS) document.layers[id].visibility = "show";
else if (isIE)
{
document.all[id].style.visibility="visible";
//de 100 geeft de doorzichtigheid aan.
setTimeout("doFadeIn('"+id+"',100)",1000);
}
else if (isDOM) document.getElementById(id).style.visibility="visible";
}

function hide(id)
{
if (isNS) document.layers[id].visibility = "hide";
else if (isIE)
{
// document.all[id].style.visibility="hidden";
setTimeout("doFadeOut('"+id+"',100)",1000)
}
else if (isDOM) document.getElementById(id).style.visibility="hidden";
}

function doFadeIn(fadeName,maxPct)
{
var fadeObj = document.all[fadeName]
if ((fadeObj.filters.alpha.opacity + 6) <= maxPct)
{
fadeObj.filters.alpha.opacity += 6;
setTimeout("doFadeIn('" + fadeObj.id + "'," + maxPct + ")",30)
}
else fadeObj.filters.alpha.opacity = maxPct;
}

function doFadeOut(fadeName,maxPct)
{
var fadeObj = document.all[fadeName]
if ((fadeObj.filters.alpha.opacity - 8) >= 0)
{
fadeObj.filters.alpha.opacity -= 8;
setTimeout("doFadeOut('" + fadeObj.id + "'," + maxPct + ")",30)
}
else fadeObj.filters.alpha.opacity = 0;
}

// -->
</script>


</head>

<body>

<div id="divtofade" style="visibility:hidden;">
Welcome
<img src='http://codingforums.com/archive/index.php/draaikolk.jpg' width="50" height="50" alt="">
</div>

<script language="javascript1.3">
<!--
setTimeout("show(\'divtofade\')",2000)
// -->
</script>

</body>

</html>

vwphillips
01-08-2006, 04:50 PM
try this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
</head>

<body onload="zxcInitOpacity('Test1',500,10,10,50);">
<center>


<div id="Test1" style="position:relative;width:100px;height:50px;background-color:red;" onmouseover="zxcOpacityDo('Test1');" ></div>
<br>
<div style="position:relative;width:100px;height:50px;background-color:blue;" onmouseout="zxcOpacityDo(this);" onmouseover="zxcOpacityDo(this,100,20,100,10);" ></div>
</center>

<script language="JavaScript" type="text/javascript">
<!--
// Element Opacity (08-12-2005)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// The element must be a element which has opacity property
// The effect is only valid for browsers which recognise the opacity property
// IE5+, Mozilla, Netscape and Konkorer
// The initial opacity may be established from a <BODY> or window onload event call
// and the effect from any event call.
// Repeating the call will reverse the effect
// There may be as many application on a page as required.

// Application Notes

// **** Initialising the Opacity

// Normally established from a <BODY> or window onload event call
// The element must be allocated a unique ID name
// e.g. <body onload="zxcInitOpacity('Test1',500,10,10,50);">
// parameter 0 = unique ID name of the element (string)
// parameter 1 = the speed (1 = fast, 500 = slow) (digit)
// parameter 2 = the number of opacity steps (digit)
// parameter 3 = the start opacity value (0 to 100) (digit)
// parameter 4 = the finish opacity value (0 to 100) (digit)

// **** Executing the Effect
// e.g. <div id="Test1" onmouseover="zxcOpacityDo('Test1',500,10,10,50);" style="position:relative;width:100px;height:50px;background-color:red;" ></div>
// Where:
// parameter 0 = object or unique ID name of the element (object or string)
// NOTE: parameters 1 to 4 only need to be specified once and if the element opacity has not been initialised
// parameter 1 = the speed (1 = fast, 500 = slow) (digit)
// parameter 2 = the number of opacity steps (digit)
// parameter 3 = the start opacity value (0 to 100) (digit)
// parameter 4 = the finish opacity value (0 to 100) (digit)



// All variable, function etc. names are prefixed with 'zxc' to minimise conflicts with other JavaScripts

// The Functional Code(about 2K) is best as an External JavaScript

// Tested with IE6 and Mozilla FireFox


// Functional Code - NO NEED to Change

var zxcCnt=0;

function zxcInitOpacity(zxcm,zxcd,zxcstp,zxcsrt,zxcfin){
if (typeof(zxcm)=='string'){ zxcm=document.getElementById(zxcm); }
if (!zxcm.oop){
zxcm.tog=true
zxcm.oop=new zxcOOPOpac(zxcm,zxcd,zxcstp,zxcsrt,zxcfin);
zxcOpacity(zxcm.style,zxcm.oop.inc[0]);
}
}

function zxcOpacityDo(zxcm,zxcd,zxcstp,zxcsrt,zxcfin){
if (typeof(zxcm)=='string'){ zxcm=document.getElementById(zxcm); }
if (!zxcm.oop){
zxcInitOpacity(zxcm,zxcd,zxcstp,zxcsrt,zxcfin);
}
clearTimeout(zxcm.oop.to);
zxcm.oop.up();
if (zxcm.tog){
zxcm.oop.updown=true;
zxcm.oop.up();
zxcm.tog=false;
}
else {
zxcm.oop.updown=false;
zxcm.oop.down();
zxcm.tog=true;
}
}

function zxcOOPOpac(zxcm,zxcd,zxcstp,zxcsrt,zxcfin){
this.obj=zxcm.style;
this.ref='zxcoopopac'+zxcCnt;
window[this.ref]=this;
this.updown=true;
this.cnt=0;
this.delay=zxcd;
this.inc=zxcSteps(zxcstp,[zxcsrt,zxcfin]);
if (zxcsrt>zxcfin){ this.inc=this.inc.reverse(); }
this.to=null;
zxcCnt++;
}

zxcOOPOpac.prototype.down=function(){
zxcOpacity(this.obj,(this.inc[this.cnt]));
if (this.cnt>0&&!this.updown){ this.cnt--; this.setTimeOut("down();",this.delay); }
}

zxcOOPOpac.prototype.up=function(){
zxcOpacity(this.obj,(this.inc[this.cnt]));
if (this.cnt<this.inc.length-1&&this.updown){ this.cnt++; this.setTimeOut("up();",this.delay); }
}

zxcOOPOpac.prototype.setTimeOut=function(zxcf,zxcd){
this.to=setTimeout("window."+this.ref+"."+zxcf,zxcd);
}

function zxcOpacity(zxcobj,zxcop) {
if (zxcop>100||zxcop<0){ return }
if (zxcobj.MozOpacity!=null){ zxcobj.MozOpacity=(zxcop/100)-.001; }
else if (zxcobj.opacity!=null){ zxcobj.opacity=(zxcop/100)-.001; }
else if (zxcobj.filter!=null){ zxcobj.filter = 'alpha(opacity='+zxcop+')'; }
else if (zxcobj.KHTMLOpacity!=null){ zxcobj.KHTMLOpacity=(zxcop/100)-.001; }
}

function zxcSteps(zxcstps,zxcsary){
zxctary=[];
for (zxc1=0;zxc1<zxcstps;zxc1++){
zxctary[zxc1]=Math.floor(Math.abs((zxcsary[0]-zxcsary[1])/(zxcstps-1))*zxc1+Math.min(zxcsary[0],zxcsary[1]))
}
if (zxcsary[2]>zxcsary[3]){ zxctary=zxctary.reverse(); }
return zxctary
}

//-->
</script>


</body>

</html>


 

TOP

Hyperthreading hurts s
HP sharpens blade PC l
Apple goes for Quad po
Itanium gets scaled do

For more info

Hyperthreading hurts s
HP sharpens blade PC l
problem with an ImageP
Modifying a navigation
convert text to intege
Anyone knows to clear 
Automatically generate
document.getElementByI
Hi question about stor
Netscape Problems :-( 

News Archive

Month and Year drop do
navigation button/imag
doubt in window.open()
undo redo script 
Mimick "View Source" w
print Question 
No-image representatio
What's wrong with this
Urgent help in Javascr
Gurt Menu assistance 

Related stories:

Urgent help in Javascript calendar display
Gurt Menu assistance
<select onChange=" "> ??
Todo es posible...
Making multiple pop-ups?
Limit Javascript to just ONE table?
Inactivity

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics