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


Posted in Javascript onMarch 22, 2007
prowin.js /** 
* @author ldgmc 
*/ 
function PopWin(id,width,title){ 
    this.id=id; 
    this.width=width; 
    this.title=title; 
    this.createIns=function(){ 
        var ins=document.createElement("div"); 
        ins.className="popWin"; 
        ins.id=this.id; 
        ins.style.width=this.width+'px'; 
        return ins;     
    }; 
    this.items=new Array(); 
    this.instance=this.createIns(); 
    this.init=function(){ 
        this.addTitle(this.title); 
        document.body.appendChild(this.instance); 
    } 
    this.addTitle=function(title){ 
        var titleDiv=document.createElement("div"); 
        titleDiv.className="title"; 
        var titleText=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){ 
        var itemDiv=ldg.common.setClassName("div","item"); 
        var itema=document.createElement("a"); 
        itema.href="#"; 
        var itemImg=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){ 
        var eObj=e.srcElement || e.target; 
        var link=document.getElementsByTagName("link"); 
        link[1].href=eObj.css; 
    } 
    this.mouseover=function(e){ 
        var eObj=e.srcElement || e.target; 
        eObj.style.backgroundColor="#e5e5e5"; 
    } 
    this.mouseout=function(e){ 
        var eObj=e.srcElement || e.target; 
        eObj.style.backgroundColor="#EEEEEE"; 
    } 
    this.click=function(e){ 
        var eObj=e.srcElement || e.target; 
        var item=this.items[eObj.id]["content"]; 
        item.style.display=="block"?item.style.display="none":item.style.display="block"; 
    } 
    this.init(); 

ldg.js 
var ldg=window.ldg || {} 
Array.prototype.append=function(item){ 
    this[this.length]=item 
} 
Function.prototype.bindAsEventListener=function(obj){ 
    var _method=this; 
    return function(event){ 
        return _method.call(obj,event || window.event); 
    } 
} 
ldg.event={ 
    addEvent:function(obj,evType,fun){ 
        if(obj.addEventListener){ 
            obj.addEventListener(evType,fun,false); 
            return true; 
        }else if(obj.attachEvent){ 
            obj.attachEvent("on"+evType,fun); 
            return true; 
        }else{return false} 
    } 
} 
ldg.common={ 
    $:function(id){ 
        return document.getElementById(id);     
    }, 
    setClassName:function(eleType,className){ 
        var element=document.createElement(eleType) 
        element.className=className; 
        return element; 
    } 
}

<html> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
        <title>testBlog</title> 
        <link rel=stylesheet type=text/css href="css/window.css"> 
        <link rel=stylesheet type=text/css href="css/bg.css"> 
        <script src="js/prpwin.js"></script> 
        <script src="js/ldg.js"></script> 
        <script> 
            window.onload=function(){         
                var pop=new PopWin(1,440,"标题"); 
                pop.addItem(1,"默认主题"); 
                pop.addItem(2,"2222"); 
                pop.addItem(3,"3333"); 
                pop.addItem(4,"4444"); 
                pop.addItemContent(1,"images/1.gif","css/bg2.css"); 
                pop.addItemContent(1,"images/2.gif","css/bg3.css"); 
                pop.addItemContent(1,"images/3.gif","css/bg4.css"); 
                pop.addItemContent(1,"images/4.gif","css/bg5.css"); 
                pop.addItemContent(1,"images/5.gif","css/bg6.css"); 
                pop.addItemContent(1,"images/1.gif","css/bg7.css"); 
                pop.addItemContent(1,"images/2.gif","css/bg8.css"); 
                pop.addItemContent(1,"images/3.gif","css/bg9.css"); 
                pop.addItemContent(1,"images/4.gif","css/bg0.css"); 
                pop.addItemContent(1,"images/5.gif","css/bg4.css"); 
                pop.addItemContent(1,"images/6.gif","css/bg2.css",true); 
                pop.addItemContent(2,"images/7.gif","css/bg8.css"); 
                pop.addItemContent(2,"images/8.gif","css/bg6.css"); 
                pop.addItemContent(2,"images/9.gif","css/bg3.css"); 
                pop.addItemContent(2,"images/10.gif","css/bg2.css"); 
                pop.addItemContent(2,"images/11.gif","css/bg6.css"); 
                pop.addItemContent(2,"images/12.gif","css/bg4.css",true); 
                pop.addItemContent(3,"images/13.gif","css/bg9.css");     
                pop.addItemContent(3,"images/14.gif","css/bg1.css");     
                pop.addItemContent(3,"images/15.gif","css/bg7.css",true); 
                pop.addItemContent(4,"images/4.gif","css/bg9.css"); 
                pop.addItemContent(4,"images/5.gif","css/bg3.css"); 
                pop.addItemContent(4,"images/1.gif","css/bg5.css"); 
                pop.addItemContent(4,"images/2.gif","css/bg2.css"); 
                pop.addItemContent(4,"images/3.gif","css/bg3.css"); 
                pop.addItemContent(4,"images/4.gif","css/bg0.css"); 
                pop.addItemContent(4,"images/5.gif","css/bg7.css"); 
                pop.addItemContent(4,"images/1.gif","css/bg4.css"); 
                pop.addItemContent(4,"images/2.gif","css/bg3.css"); 
                pop.addItemContent(4,"images/4.gif","css/bg7.css"); 
                pop.addItemContent(4,"images/5.gif","css/bg1.css"); 
                pop.addItemContent(4,"images/4.gif","css/bg1.css",true); 
            }         </script> 
    </head> 
    <body> 
    </body> 
</html>
Javascript 相关文章推荐
JS学习之一个简易的日历控件
Mar 24 Javascript
document.execCommand()的用法小结
Jan 08 Javascript
js中array的sort()方法使用介绍
Feb 20 Javascript
Jquery 在页面加载后执行的几种方式
Mar 14 Javascript
JavaScript中逗号运算符介绍及使用示例
Mar 13 Javascript
jquery实现经典的淡入淡出选项卡效果代码
Sep 22 Javascript
基于Jquery代码实现手风琴菜单
Nov 19 Javascript
Angular和百度地图的结合实例代码
Oct 19 Javascript
javascript中递归的两种写法
Jan 17 Javascript
JS获取填报扩展单元格控件的值的解决办法
Jul 14 Javascript
详解javascript replace高级用法
Feb 17 Javascript
详解vue.js移动端配置flexible.js及注意事项
Apr 10 Javascript
漂亮的提示信息(带箭头)
Mar 21 #Javascript
自动生成文章摘要的代码[JavaScript 版本]
Mar 20 #Javascript
用roll.js实现的图片自动滚动+鼠标触动的特效
Mar 18 #Javascript
表单提交时自动复制内容到剪贴板的js代码
Mar 16 #Javascript
用javascript自动显示最后更新时间
Mar 15 #Javascript
用js实现预览待上传的本地图片
Mar 15 #Javascript
从新浪弄下来的全屏广告代码 与使用说明
Mar 15 #Javascript
You might like
Yii实现自动加载类地图的方法
2015/04/01 PHP
CodeIgniter扩展核心类实例详解
2016/01/20 PHP
javascript应用:Iframe自适应其加载的内容高度
2007/04/10 Javascript
Javascript this 的一些学习总结
2012/08/02 Javascript
用js调用迅雷下载代码的二种方法
2013/04/15 Javascript
JS的location.href跳出框架打开新页面的方法
2014/09/04 Javascript
jQuery结合CSS制作漂亮的select下拉菜单
2015/05/03 Javascript
jQuery操作dom实现弹出页面遮罩层(web端和移动端阻止遮罩层的滑动)
2016/08/25 Javascript
JS动态计算移动端rem的解决方案
2016/10/14 Javascript
react.js 获取真实的DOM节点实例(必看)
2017/04/17 Javascript
详解angularJS动态生成的页面中ng-click无效解决办法
2017/06/19 Javascript
AngularJS2 与 D3.js集成实现自定义可视化的方法
2017/12/01 Javascript
浅谈AngularJs 双向绑定原理(数据绑定机制)
2017/12/07 Javascript
JS弹窗 JS弹出DIV并使整个页面背景变暗功能的实现代码
2018/04/21 Javascript
基于Vue 服务端Cookies删除的问题
2018/09/21 Javascript
vue实现权限控制路由(vue-router 动态添加路由)
2019/11/04 Javascript
jQuery实现开关灯效果
2020/08/02 jQuery
[04:10]DOTA2英雄梦之声_第11期_圣堂刺客
2014/06/21 DOTA
[08:04]TI4西雅图DOTA2前线报道 海涛探访各路人马
2014/07/09 DOTA
Python最基本的数据类型以及对元组的介绍
2015/04/14 Python
Python简单生成8位随机密码的方法
2017/05/24 Python
如何在python中使用selenium的示例
2017/12/26 Python
DataFrame中的object转换成float的方法
2018/04/10 Python
python获取url的返回信息方法
2018/12/17 Python
Python实现的IP端口扫描工具类示例
2019/02/15 Python
python f-string式格式化听语音流程讲解
2019/06/18 Python
Python3.7在anaconda里面使用IDLE编译器的步骤详解
2020/04/29 Python
一文详述 Python 中的 property 语法
2020/09/01 Python
C#可否对内存进行直接的操作
2015/02/26 面试题
质量标语大全
2014/06/12 职场文书
战友聚会策划方案
2014/06/13 职场文书
标准大学生职业生涯规划书写作指南
2014/09/18 职场文书
爱心捐款感谢信
2015/01/20 职场文书
2015年“七七卢沟桥事变”纪念活动总结
2015/03/24 职场文书
2019最新校园运动会广播稿!
2019/06/28 职场文书
用Python提取PDF表格的方法
2021/04/11 Python