The link color.
抄来的代码,用于实现链接颜色渐变效果,还美完全学会用,备个份。
var rmsOOPCnt=0;
document.onmouseover = doEffect;
//document.onmouseout = doEffect;
function doEffect(event) {
event = (event) ? event : (window.event) ? window.event : '';
if( event ) {
rmsobjElem = (event.target) ? event.target : event.srcElement;
tagLink = rmsobjElem.getElementsByTagName("a");
if( rmsobjElem.className == 'postTitle' ) {
if(tagLink[0].href) {
rmsAnimator('color', tagLink[0], '#FFFFFF', '#014401', 'sin', 800);
tagLink[0].mouseout = rmsAnimator('color', rmsobjElem, '#014401', '#FFFFFF', 'sin', 400);
}
}
}
}
function rmsAnimator(rmsmde,rmsobj,rmssrt,rmsfin,rmscurve,rmstime,rmsborder){
if (typeof(rmsobj)=='string'){ rmsobj=document.getElementById(rmsobj); }
if (!rmsobj||(!rmssrt&&!rmsfin)||rmssrt==rmsfin) return;
var rmsoop=rmsobj[rmsmde.replace('-','')+'oop'];
if (rmsoop){
rmssrt=rmsNuRGB(rmssrt);
rmsfin=rmsNuRGB(rmsfin);
if (rmsCkArray(rmssrt,rmsoop.data[1]) && rmsCkArray(rmsfin,rmsoop.data[2]))
rmsoop.update([rmsoop.data[0],rmssrt],rmscurve,rmstime,rmsborder);
else
rmsoop.update([rmssrt,rmsfin],rmscurve,rmstime,rmsborder);
}
else rmsobj[rmsmde.replace('-','')+'oop']=new rmsAnimatorOOP(rmsmde,rmsobj,rmssrt,rmsfin,rmscurve,rmstime,rmsborder);
}
function rmsAnimatorOOP(rmsmde,rmsobj,rmssrt,rmsfin,rmscurve,rmstime,rmsborder){
if (rmsStyleValue(rmsobj,'position')=='static'&&(rmsmde=='left'||rmsmde=='top')) rmsobj.style.position='relative';
this.units=rmssrt.toString().replace(/\d/g,'')||'px';
this.to=null;
this.obj=rmsobj;
this.mde=rmsmde;
this.update([rmsNuRGB(rmssrt),rmsNuRGB(rmsfin)],rmscurve,rmstime,rmsborder);
}
rmsAnimatorOOP.prototype.update=function(rmssrtfin,rmscurve,rmstime,rmsborder){
clearTimeout(this.to);
rmscurve=rmscurve||this.curve||'';
this.time=rmstime||this.time||2000;
if (rmssrtfin[0]==rmssrtfin[1]) return;
for (var rms0=0;rms0<rmssrtfin.length;rms0++){
var rmsobj=document.getElementById(rmssrtfin[rms0]);
if (rmsobj){ rmssrtfin[rms0]=rmsStyleValue(rmsobj,rmsmde); if (!this.mde.match('olor')) rmssrtfin[rms0]=parseInt(rmssrtfin[rms0]); }
if (rmssrtfin[rms0]==0) rmssrtfin[rms0]=0.00001;
}
if (this.mde=='opacity'&&(rmssrtfin[0]<0||rmssrtfin[0]>100||rmssrtfin[0]<0||rmssrtfin[0]>100)) return;
if (rmsborder) this.brd=rmsborder.split(' ');
this.curve=rmscurve.charAt(0).toLowerCase();
var rmsmatch=rmssrtfin[0].toString();
this.data=[[],rmssrtfin[0],rmssrtfin[1]];
for (var rms0 in this.data[1]) this.data[0].push(this.data[1][rms0]);
this.srttime=new Date().getTime();
this.inc=Math.PI/(2*this.time);
this.cng();
}
rmsAnimatorOOP.prototype.cng=function(){
var rmsms=new Date().getTime()-this.srttime;
for (var rms0 in this.data[2]){ this.data[0][rms0]=(this.curve=='s')?Math.floor((this.data[2][rms0]-this.data[1][rms0])*Math.sin(this.inc*rmsms)+this.data[1][rms0]):(this.curve=='c')?(this.data[2][0])-Math.floor((this.data[2][rms0]-this.data[1][rms0])*Math.cos(this.inc*rmsms)):(this.data[2][rms0]-this.data[1][rms0])/this.time*rmsms+this.data[1][rms0]; }
this.cngstyle(this.data[0]);
if (rmsms<this.time) this.to=setTimeout(function(rmsoop){return function(){rmsoop.cng();}}(this), 10);
else this.cngstyle(this.data[2]);
}
rmsAnimatorOOP.prototype.cngstyle=function(rmspar){
if (this.mde.match('border')){
if (rmspar.length==1) this.obj.style[this.mde.replace('-','')]=this.brd[0]+' '+this.brd[1]+' '+rmspar[0]+this.units;
if (rmspar.length==3) this.obj.style[this.mde.replace('-','')]=this.brd[0]+' rgb('+rmspar[0]+','+rmspar[1]+','+rmspar[2]+') '+this.brd[2];
}
else if (this.mde.match('olor')) this.obj.style[this.mde.replace('-','')]='rgb('+rmspar[0]+','+rmspar[1]+','+rmspar[2]+')';
else if (this.mde!='opacity') this.obj.style[this.mde]=rmspar[0]+this.units;
else this.opacity(rmspar[0]);
}
rmsAnimatorOOP.prototype.opacity=function(rmsopc){
if (rmsopc<0||rmsopc>100) return;
if (this.obj.style.MozOpacity!=null) this.obj.style.MozOpacity=(rmsopc/100)-.001;
else if (this.obj.style.opacity!=null) this.obj.style.opacity=(rmsopc/100)-.001;
else if (this.obj.style.filter!=null) this.obj.style.filter='alpha(opacity='+rmsopc+')';
else if (this.obj.KHTMLOpacity!=null) this.obj.KHTMLOpacity=(rmsopc/100)-.001;
}
function rmsStyleValue(rmsel,rmsp){
if (rmsel.currentStyle) return rmsel.currentStyle[rmsp.replace('-','')];
return document.defaultView.getComputedStyle(rmsel,null).getPropertyValue(rmsp.toLowerCase());
}
function rmsNuRGB(rmscol)
{
if( !rmscol.toString().match('#') )
{
return [parseInt(rmscol)];
}
rmscol=parseInt(rmscol.substring(1,3),16)+', '+parseInt(rmscol.substring(3,5),16)+','+parseInt(rmscol.substring(5,7),16);
rmscol=rmscol.replace(/[rgb()\s]/g,'').split(',');
return [parseInt(rmscol[0]), parseInt(rmscol[1]), parseInt(rmscol[2])];
}
function rmsCkArray(rmsary,rmsdata) {
for( var rms0 = 0; rms0 < rmsary.length; rms0++ )
{
if( rmsary[rms0] != rmsdata[rms0] )
{
return false;
}
}
return true;
}
document.onmouseover = doEffect;
//document.onmouseout = doEffect;
function doEffect(event) {
event = (event) ? event : (window.event) ? window.event : '';
if( event ) {
rmsobjElem = (event.target) ? event.target : event.srcElement;
tagLink = rmsobjElem.getElementsByTagName("a");
if( rmsobjElem.className == 'postTitle' ) {
if(tagLink[0].href) {
rmsAnimator('color', tagLink[0], '#FFFFFF', '#014401', 'sin', 800);
tagLink[0].mouseout = rmsAnimator('color', rmsobjElem, '#014401', '#FFFFFF', 'sin', 400);
}
}
}
}
function rmsAnimator(rmsmde,rmsobj,rmssrt,rmsfin,rmscurve,rmstime,rmsborder){
if (typeof(rmsobj)=='string'){ rmsobj=document.getElementById(rmsobj); }
if (!rmsobj||(!rmssrt&&!rmsfin)||rmssrt==rmsfin) return;
var rmsoop=rmsobj[rmsmde.replace('-','')+'oop'];
if (rmsoop){
rmssrt=rmsNuRGB(rmssrt);
rmsfin=rmsNuRGB(rmsfin);
if (rmsCkArray(rmssrt,rmsoop.data[1]) && rmsCkArray(rmsfin,rmsoop.data[2]))
rmsoop.update([rmsoop.data[0],rmssrt],rmscurve,rmstime,rmsborder);
else
rmsoop.update([rmssrt,rmsfin],rmscurve,rmstime,rmsborder);
}
else rmsobj[rmsmde.replace('-','')+'oop']=new rmsAnimatorOOP(rmsmde,rmsobj,rmssrt,rmsfin,rmscurve,rmstime,rmsborder);
}
function rmsAnimatorOOP(rmsmde,rmsobj,rmssrt,rmsfin,rmscurve,rmstime,rmsborder){
if (rmsStyleValue(rmsobj,'position')=='static'&&(rmsmde=='left'||rmsmde=='top')) rmsobj.style.position='relative';
this.units=rmssrt.toString().replace(/\d/g,'')||'px';
this.to=null;
this.obj=rmsobj;
this.mde=rmsmde;
this.update([rmsNuRGB(rmssrt),rmsNuRGB(rmsfin)],rmscurve,rmstime,rmsborder);
}
rmsAnimatorOOP.prototype.update=function(rmssrtfin,rmscurve,rmstime,rmsborder){
clearTimeout(this.to);
rmscurve=rmscurve||this.curve||'';
this.time=rmstime||this.time||2000;
if (rmssrtfin[0]==rmssrtfin[1]) return;
for (var rms0=0;rms0<rmssrtfin.length;rms0++){
var rmsobj=document.getElementById(rmssrtfin[rms0]);
if (rmsobj){ rmssrtfin[rms0]=rmsStyleValue(rmsobj,rmsmde); if (!this.mde.match('olor')) rmssrtfin[rms0]=parseInt(rmssrtfin[rms0]); }
if (rmssrtfin[rms0]==0) rmssrtfin[rms0]=0.00001;
}
if (this.mde=='opacity'&&(rmssrtfin[0]<0||rmssrtfin[0]>100||rmssrtfin[0]<0||rmssrtfin[0]>100)) return;
if (rmsborder) this.brd=rmsborder.split(' ');
this.curve=rmscurve.charAt(0).toLowerCase();
var rmsmatch=rmssrtfin[0].toString();
this.data=[[],rmssrtfin[0],rmssrtfin[1]];
for (var rms0 in this.data[1]) this.data[0].push(this.data[1][rms0]);
this.srttime=new Date().getTime();
this.inc=Math.PI/(2*this.time);
this.cng();
}
rmsAnimatorOOP.prototype.cng=function(){
var rmsms=new Date().getTime()-this.srttime;
for (var rms0 in this.data[2]){ this.data[0][rms0]=(this.curve=='s')?Math.floor((this.data[2][rms0]-this.data[1][rms0])*Math.sin(this.inc*rmsms)+this.data[1][rms0]):(this.curve=='c')?(this.data[2][0])-Math.floor((this.data[2][rms0]-this.data[1][rms0])*Math.cos(this.inc*rmsms)):(this.data[2][rms0]-this.data[1][rms0])/this.time*rmsms+this.data[1][rms0]; }
this.cngstyle(this.data[0]);
if (rmsms<this.time) this.to=setTimeout(function(rmsoop){return function(){rmsoop.cng();}}(this), 10);
else this.cngstyle(this.data[2]);
}
rmsAnimatorOOP.prototype.cngstyle=function(rmspar){
if (this.mde.match('border')){
if (rmspar.length==1) this.obj.style[this.mde.replace('-','')]=this.brd[0]+' '+this.brd[1]+' '+rmspar[0]+this.units;
if (rmspar.length==3) this.obj.style[this.mde.replace('-','')]=this.brd[0]+' rgb('+rmspar[0]+','+rmspar[1]+','+rmspar[2]+') '+this.brd[2];
}
else if (this.mde.match('olor')) this.obj.style[this.mde.replace('-','')]='rgb('+rmspar[0]+','+rmspar[1]+','+rmspar[2]+')';
else if (this.mde!='opacity') this.obj.style[this.mde]=rmspar[0]+this.units;
else this.opacity(rmspar[0]);
}
rmsAnimatorOOP.prototype.opacity=function(rmsopc){
if (rmsopc<0||rmsopc>100) return;
if (this.obj.style.MozOpacity!=null) this.obj.style.MozOpacity=(rmsopc/100)-.001;
else if (this.obj.style.opacity!=null) this.obj.style.opacity=(rmsopc/100)-.001;
else if (this.obj.style.filter!=null) this.obj.style.filter='alpha(opacity='+rmsopc+')';
else if (this.obj.KHTMLOpacity!=null) this.obj.KHTMLOpacity=(rmsopc/100)-.001;
}
function rmsStyleValue(rmsel,rmsp){
if (rmsel.currentStyle) return rmsel.currentStyle[rmsp.replace('-','')];
return document.defaultView.getComputedStyle(rmsel,null).getPropertyValue(rmsp.toLowerCase());
}
function rmsNuRGB(rmscol)
{
if( !rmscol.toString().match('#') )
{
return [parseInt(rmscol)];
}
rmscol=parseInt(rmscol.substring(1,3),16)+', '+parseInt(rmscol.substring(3,5),16)+','+parseInt(rmscol.substring(5,7),16);
rmscol=rmscol.replace(/[rgb()\s]/g,'').split(',');
return [parseInt(rmscol[0]), parseInt(rmscol[1]), parseInt(rmscol[2])];
}
function rmsCkArray(rmsary,rmsdata) {
for( var rms0 = 0; rms0 < rmsary.length; rms0++ )
{
if( rmsary[rms0] != rmsdata[rms0] )
{
return false;
}
}
return true;
}
meiking
2008-06-17 11:17:03
评论:0
阅读:28
引用:0
