欢迎来到福编程网,本站提供各种互联网专业知识!

用js实现的仿sohu博客更换页面风格(简单版)

发布时间:2007-03-22 作者: 来源:转载
复制代码代码如下:prowin.js/***@authorldgmc*/functionPopWin(id,width,title){this.id=id;this.width=width;this.title=title;this.createIns=function(){varins=document.createElement("div");ins.className="popWin";ins.id=this.id;ins.sty
复制代码 代码如下:
prowin.js

/**
*@authorldgmc
*/
functionPopWin(id,width,title){
this.id=id;
this.width=width;
this.title=title;
this.createIns=function(){
varins=document.createElement("div");
ins.className="popWin";
ins.id=this.id;
ins.style.width=this.width+'px';
returnins;
};
this.items=newArray();
this.instance=this.createIns();
this.init=function(){
this.addTitle(this.title);
document.body.appendChild(this.instance);
}
this.addTitle=function(title){
vartitleDiv=document.createElement("div");
titleDiv.className="title";
vartitleText=document.createTextNode(title);
titleDiv.appendChild(titleText);
this.instance.appendChild(titleDiv);
}
this.addItem=function(id,title){
this.items[id]={};
this.items[id]["title"]=ldg.common.setClassName("div","itemTitle");
this.items[id]["title"].appendChild(document.createTextNode(title));
this.items[id]["content"]=ldg.common.setClassName("div","itemContent");
this.items[id]["title"].id=id;
ldg.event.addEvent(this.items[id]["title"],"mouseover",this.mouseover.bindAsEventListener(this))
ldg.event.addEvent(this.items[id]["title"],"mouseout",this.mouseout.bindAsEventListener(this));
ldg.event.addEvent(this.items[id]["title"],"click",this.click.bindAsEventListener(this));
this.instance.appendChild(this.items[id]["title"]);
this.instance.appendChild(this.items[id]["content"]);
}
this.addItemContent=function(parentId,imgUri,cssUri,isLast){
varitemDiv=ldg.common.setClassName("div","item");
varitema=document.createElement("a");
itema.href="#";
varitemImg=document.createElement("img");
itemImg.src=imgUri;
itemImg.css=cssUri;
ldg.event.addEvent(itemImg,"click",this.changeLink.bindAsEventListener(this));
itema.appendChild(itemImg);
itemDiv.appendChild(itema);
this.items[parentId]["content"].appendChild(itemDiv);
if(isLast){
this.items[parentId]["content"].appendChild(document.createElement("br"));
}

}
this.changeLink=function(e){
vareObj=e.srcElement||e.target;
varlink=document.getElementsByTagName("link");
link[1].href=eObj.css;
}
this.mouseover=function(e){
vareObj=e.srcElement||e.target;
eObj.style.backgroundColor="#e5e5e5";
}
this.mouseout=function(e){
vareObj=e.srcElement||e.target;
eObj.style.backgroundColor="#EEEEEE";
}
this.click=function(e){
vareObj=e.srcElement||e.target;
varitem=this.items[eObj.id]["content"];
item.style.display=="block"?item.style.display="none":item.style.display="block";
}
this.init();

复制代码 代码如下:
ldg.js
varldg=window.ldg||{}
Array.prototype.append=function(item){
this[this.length]=item
}
Function.prototype.bindAsEventListener=function(obj){
var_method=this;
returnfunction(event){
return_method.call(obj,event||window.event);
}
}
ldg.event={
addEvent:function(obj,evType,fun){
if(obj.addEventListener){
obj.addEventListener(evType,fun,false);
returntrue;
}elseif(obj.attachEvent){
obj.attachEvent("on"+evType,fun);
returntrue;
}else{returnfalse}
}
}
ldg.common={
$:function(id){
returndocument.getElementById(id);
},
setClassName:function(eleType,className){
varelement=document.createElement(eleType)
element.className=className;
returnelement;
}
}

复制代码 代码如下:



testBlog







相关推荐