我的收藏!(一些常用的函数)
不好意思学人家授人予渔,我认为使用这些函数足可以制作出各种特效。我就是这么做的,现在送给大家。(因为心情不好,面临很多债务,more than 2M¥,烦死了,我还很年轻的,以后怎么过)
1、为了提高适用性,检查浏览器版本
function lib_bwcheck(){ this.ver=navigator.appVersion;
this.agent=navigator.userAgent
this.dom=document.getElementById?1:0
this.win = (navigator.appVersion.indexOf("Win")>0);
this.xwin = (navigator.appVersion.indexOf("X11")>0);
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
this.ie4=(document.all && !this.dom)?1:0;
this.ie=this.ie4||this.ie5||this.ie6
this.mac=this.agent.indexOf("Mac")>-1
this.opera5=this.agent.indexOf("Opera 5")>-1
this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
this.ns4=(document.layers && !this.dom)?1:0;
this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.dom||false);
this.width = null;
this.height = null;
return this
}
例如 var bw = new lib_bwcheck();//指需要实例一个bw,建议bw,因为后面的函数中我使用bw检查浏览器
2、一个层的“类”,包含了一些常用的方法和属性
function oLayer( idStr ) {
this.idStr = idStr;
if(bw.ns4)this.idPtr=document.layers[idStr];
else if (bw.ns6) this.idPtr = document.getElementById(idStr);
else this.idPtr = eval('document.all.'+idStr);
//----------方法-------
//this.makeAnimate = makeAnimate; //用于产生移动图层的动画效果
this.moveTo=lib_moveTo;
this.moveBy=lib_moveBy;
this.clipTo=lib_clipTo;
this.show=lib_showIt;
this.hide=lib_hideIt;
this.zoomTo=lib_zoomTo; //缩放图层
this.setBgColor=lib_setBgC;
//---------属性-------
this.x = getLayerX(this.idStr);
this.y = getLayerY(this.idStr);
this.z = getZIndex(this.idStr);
this.sh = getLayerSH(this.idStr);
this.sw = getLayerSW(this.idStr);
if (bw.ns6) this.css=this.idPtr.style;
else if (bw.ns) this.css=this.idPtr;
else this.css=this.idPtr.style;
return (this);
}
function lib_clipTo(t,r,b,l,setwidth){ //改变图层大小
if(t<0)t=0;
if(r<0)r=0;
if(b<0)b=0;
if(l<0)l=0;
this.ct=t;
this.cr=r;
this.cb=b;
this.cl=l
if(bw.ns4){
this.css.clip.top=t;
this.css.clip.right=r;
this.css.clip.bottom=b;
this.css.clip.left=l;
}else if(bw.opera5){
this.css.pixelWidth=r;
this.css.pixelHeight=b;
this.w=r;
this.h=b
}else{
this.css.clip="rect("+t+","+r+","+b+","+l+")";
if(setwidth){
this.css.width=r;
this.css.height=b;
this.w=r;
this.h=b
}
}
}
function lib_zoomTo(scale){
this.scale=scale;
this.css.zoom=scale;
}
function lib_moveTo(x,y){
this.x=x!=''?x:this.x;
this.y=y!=''?y:this.y;
this.css.left=this.x;
this.css.top=this.y
}
function lib_moveBy(x,y){
this.moveTo(this.x+x,this.y+y)
}
function lib_showIt(){
this.css.visibility="visible";
this.visible=true;
}
function lib_hideIt(){
this.css.visibility="hidden";
this.visible=false;
}
function lib_setBgC(color){
if(bw.opera5) this.css.background=color;
else if(bw.dom || bw.ie4||bw.ns6) this.css.backgroundColor=color;
else if(bw.ns4) this.css.bgColor=color ;
}
例如:oWin=new oLayer('层id'),那么要移动层到(100,200)就可以oWin.moveTo(100,200);而不需要再检查浏览器类型