Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<style type="text/css">
/*<![CDATA[*/
.fader {
width:400px;height:50px;border:solid red 1px;text-Align:center;font-Size:18px;background-Color:#FFFFCC;
}
.fader IMG {
position:relative;height:30px;top:8px;
}
/*]]>*/
</style>
</head>
<body>
<div id="tst" class="fader" onmouseover="zxcTextImagetFader.Pause('tst');" onmouseout="zxcTextImagetFader.Auto('tst');">
</div>
<br />
<br />
<div id="tst2" class="fader" onmouseover="zxcTextImagetFader.Pause('tst2');" onmouseout="zxcTextImagetFader.Auto('tst2');">
</div>
<script type="text/javascript">
/*<![CDATA[*/
// Text Image Fader. (18-December-2012)
// by Vic Phillips - http://www.vicsjavascripts.org.uk/
var zxcTextImagetFader={
init:function(o){
var id=o.ID,incol=this.rgb(o.FadeInColor,[0,0,0]),outc=this.rgb(o.FadeOutColor,[255,255,255]),ms=o.FadeDuration,holdin=o.HoldIn,holdout=o.HoldOut,ary=o.Array,obj=document.getElementById(id),ms=typeof(ms)=='number'?ms:1000;
o=zxcTextImagetFader['zxc'+id]={
obj:obj,
ary:ary,
cnt:0,
col:[incol,outc],
ms:ms,
holdin:typeof(holdin)=='number'?holdin:ms*4,
holdout:typeof(holdout)=='number'?holdout:500,
ud:false,
auto:true
}
this.fade(o,false);
},
Pause:function(id){
var o=zxcTextImagetFader['zxc'+id];
if (o){
clearTimeout(o.to);
o.auto=false;
}
},
Auto:function(id){
var o=zxcTextImagetFader['zxc'+id],oop=this;
if (o){
o.to=setTimeout(function(){ o.auto=true; oop.fade(o,!o.ud); },200);
}
},
fade:function(o,ud){
o.ud=ud;
if (ud){
o.cnt=++o.cnt%o.ary.length;
}
else {
o.obj.innerHTML=o.ary[o.cnt];
o.imgs=o.obj.getElementsByTagName('IMG');
}
this.animate(o,o.obj,'color',o.col[ud?0:1],o.col[ud?1:0],new Date(),o.ms,ud);
for (var z0=0;z0<o.imgs.length;z0++){
this.animate(o,o.imgs[z0],'',[ud?100:0],[ud?0:100],new Date(),o.ms,false);
}
},
animate:function(o,obj,mde,f,t,srt,mS,ud){
var oop=this,ms=new Date().getTime()-srt,n=[],z0=0;
for (;z0<f.length;z0++){
n[z0]=(t[z0]-f[z0])/mS*ms+f[z0];
}
if (mde=='color'){
obj.style.color='rgb('+parseInt(n[0])+','+parseInt(n[1])+','+parseInt(n[2])+')';
}
else {
this.opac(obj,n[0]);
}
if (ms<mS){
f[3]=setTimeout(function(){ oop.animate(o,obj,mde,f,t,srt,mS,ud); },10);
}
else {
if (mde=='color'){
obj.style.color='rgb('+t[0]+','+t[1]+','+t[2]+')';
if (o.auto){
o.to=setTimeout(function(){ oop.fade(o,!ud); },ud?o.holdout:o.holdin);
}
}
else {
this.opac(obj,t[0]);
}
}
},
opac:function(o,n){
o.style.filter='alpha(opacity='+n+')';
o.style.opacity=o.style.MozOpacity=o.style.WebkitOpacity=o.style.KhtmlOpacity=n/100-.001;
},
rgb:function(hex,col){
if (typeof(c)=='string'){
hex=hex.replace('#','');
if (hex.length==6){
col=[Math.min(Math.max(parseInt(hex.substring(0,2),16),0),255),Math.min(Math.max(parseInt(hex.substring(2,4),16),0),255),Math.min(Math.max(parseInt(hex.substring(4),16),0),255)];
}
}
return col;
}
}
zxcTextImagetFader.init({
ID:'tst', // the unique ID name of the parent node. (string)
Array:[ // an array of HTML code to diusplay. (array)
'text 1 <img src="http://www.sovgraceopc.org/images/cross.png" /> text 2',
'text 3',
'<img src="http://www.vicsjavascripts.org.uk/StdImages/2.gif" /> text 4 <img src="http://www.vicsjavascripts.org.uk/StdImages/2.gif" />'
],
FadeInColor:'#000000', //(optional) the fade in color as HEX. (string, default = '#000000')
FadeOutColor:'#FFFFCC', //(optional) the fade out color as HEX. (string, default = '#FFFFFF')
FadeDuration:1000, //(optional) the duration in milli seconds. (number, default = 1000)
HoldIn:2000, //(optional) the fade in hold delay in milli seconds. (number, default = FadeDuration*4)
HoldOut:200 //(optional) the fade out hold delay in milli seconds. (number, default = 500)
});
zxcTextImagetFader.init({
ID:'tst2',
Array:[
'text 1 <img src="http://www.sovgraceopc.org/images/cross.png" /> text 2',
'text 3',
'<img src="http://www.vicsjavascripts.org.uk/StdImages/2.gif" /> text 4 <img src="http://www.vicsjavascripts.org.uk/StdImages/3.gif" />'
]
});
/*]]>*/
</script>
</body>
</html>
the script you linked to faded the text by changing the color of the text which I did in the script above and used opacity for the images
however it is easier to use opacity for the complete DIV(this may distort the text)
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<style type="text/css">
/*<![CDATA[*/
.fader {
width:400px;height:50px;border:solid red 1px;text-Align:center;font-Size:18px;background-Color:#FFFFCC;
}
.fader IMG {
position:relative;height:30px;top:8px;
}
/*]]>*/
</style>
</head>
<body>
<div class="fader" >
<div id="tst" onmouseover="zxcFader.Pause('tst');" onmouseout="zxcFader.Auto('tst');">
</div>
</div>
<br />
<br />
<div class="fader" >
<div id="tst2" onmouseover="zxcFader.Pause('tst2');" onmouseout="zxcFader.Auto('tst2');">
</div>
</div>
<script type="text/javascript">
/*<![CDATA[*/
// Fader. (18-December-2012)
// by Vic Phillips - http://www.vicsjavascripts.org.uk/
var zxcFader={
init:function(o){
var id=o.ID,ms=o.FadeDuration,holdin=o.HoldIn,holdout=o.HoldOut,ary=o.Array,obj=document.getElementById(id),ms=typeof(ms)=='number'?ms:1000;
o=zxcFader['zxc'+id]={
obj:obj,
ary:ary,
cnt:0,
ms:ms,
holdin:typeof(holdin)=='number'?holdin:ms*4,
holdout:typeof(holdout)=='number'?holdout:500,
ud:false,
auto:true
}
this.fade(o,false);
},
Pause:function(id){
var o=zxcFader['zxc'+id];
if (o){
clearTimeout(o.to);
o.auto=false;
}
},
Auto:function(id){
var o=zxcFader['zxc'+id],oop=this;
if (o){
o.to=setTimeout(function(){ o.auto=true; oop.fade(o,!o.ud); },200);
}
},
fade:function(o,ud){
o.ud=ud;
if (ud){
o.cnt=++o.cnt%o.ary.length;
}
else {
o.obj.innerHTML=o.ary[o.cnt];
}
this.animate(o,o.obj,'',ud?100:0,ud?0:100,new Date(),o.ms,ud);
},
animate:function(o,obj,mde,f,t,srt,mS,ud){
var oop=this,ms=new Date().getTime()-srt,n=[],n=(t-f)/mS*ms+f;
this.opac(obj,n);
if (ms<mS){
f[3]=setTimeout(function(){ oop.animate(o,obj,mde,f,t,srt,mS,ud); },10);
}
else {
this.opac(obj,t[0]);
if (o.auto){
o.to=setTimeout(function(){ oop.fade(o,!ud); },ud?o.holdout:o.holdin);
}
}
},
opac:function(o,n){
o.style.filter='alpha(opacity='+n+')';
o.style.opacity=o.style.MozOpacity=o.style.WebkitOpacity=o.style.KhtmlOpacity=n/100-.001;
}
}
zxcFader.init({
ID:'tst', // the unique ID name of the parent node. (string)
Array:[ // an array of HTML code to diusplay. (array)
'text 1 <img src="http://www.sovgraceopc.org/images/cross.png" /> text 2',
'text 3',
'<img src="http://www.vicsjavascripts.org.uk/StdImages/2.gif" /> text 4 <img src="http://www.vicsjavascripts.org.uk/StdImages/2.gif" />'
],
FadeDuration:1000, //(optional) the duration in milli seconds. (number, default = 1000)
HoldIn:2000, //(optional) the fade in hold delay in milli seconds. (number, default = FadeDuration*4)
HoldOut:200 //(optional) the fade out hold delay in milli seconds. (number, default = 500)
});
zxcFader.init({
ID:'tst2',
Array:[
'text 1 <img src="http://www.sovgraceopc.org/images/cross.png" /> text 2',
'text 3',
'<img src="http://www.vicsjavascripts.org.uk/StdImages/2.gif" /> text 4 <img src="http://www.vicsjavascripts.org.uk/StdImages/2.gif" />'
]});
/*]]>*/
</script>
</body>
</html>
Bookmarks