用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文件的三种方法
Nov 08 Javascript
利用js实现在浏览器状态栏显示访问者在本页停留的时间
Dec 29 Javascript
jquery通过visible来判断标签是否显示或隐藏
May 08 Javascript
JS生成随机字符串的多种方法
Jun 10 Javascript
JavaScript DOM操作表格及样式
Apr 13 Javascript
JS实现随机乱撞彩色圆球特效的方法
May 05 Javascript
jQuery旋转木马式幻灯片轮播特效
Dec 04 Javascript
JavaScript实现点击按钮复制指定区域文本(推荐)
Nov 25 Javascript
jQuery实现返回顶部按钮和scroll滚动功能[带动画效果]
Jul 05 jQuery
详解React Native 采用Fetch方式发送跨域POST请求
Nov 15 Javascript
详解bootstrap导航栏.nav与.navbar区别
Nov 23 Javascript
Vue+Vux项目实践完整代码
Nov 30 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
win7计划任务定时执行PHP脚本设置图解
2014/05/09 PHP
php使用curl获取https请求的方法
2015/02/11 PHP
PHP网站建设的流程与步骤分享
2015/09/25 PHP
PHP中strtr与str_replace函数运行性能简单测试示例
2019/06/22 PHP
javascript 控制弹出窗口
2007/04/10 Javascript
javascript之学会吝啬 精简代码
2010/04/25 Javascript
js 上传图片预览问题
2010/12/06 Javascript
通过JS获取用户本地图片路径并显示的代码
2012/02/16 Javascript
javascript的回调函数应用示例
2014/02/20 Javascript
cocos2dx骨骼动画Armature源码剖析(三)
2015/09/08 Javascript
基于jQuery和hwSlider实现内容左右滑动切换效果附源码下载(一)
2016/06/22 Javascript
jQuery双向列表选择器select版
2016/11/01 Javascript
JavaScript实现汉字转换为拼音的库文件示例
2016/12/22 Javascript
Angular2监听页面大小变化的解决方法
2017/10/09 Javascript
Angular使用cli生成自定义文件、组件的方法
2018/09/04 Javascript
微信小程序中的上拉、下拉菜单功能
2020/03/13 Javascript
JavaScript find()方法及返回数据实例
2020/04/30 Javascript
JavaScript变量Dom对象的所有属性
2020/04/30 Javascript
OpenLayers3实现对地图的基本操作
2020/09/28 Javascript
vant 中van-list的用法说明
2020/11/11 Javascript
python处理大数字的方法
2015/05/27 Python
python并发编程之线程实例解析
2017/12/27 Python
Python Flask前后端Ajax交互的方法示例
2018/07/31 Python
python opencv 二值化 计算白色像素点的实例
2019/07/03 Python
pycharm下配置pyqt5的教程(anaconda虚拟环境下+tensorflow)
2020/03/25 Python
如何把外网python虚拟环境迁移到内网
2020/05/18 Python
Python2.x与3​​.x版本有哪些区别
2020/07/09 Python
戴尔美国官方折扣店:Dell Outlet
2018/02/13 全球购物
单位提档介绍信
2014/01/17 职场文书
股票投资建议书
2014/05/19 职场文书
民生工作实施方案
2014/05/31 职场文书
死者家属慰问信
2015/03/24 职场文书
中学政教处工作总结
2015/08/13 职场文书
关于国庆节的广播稿
2015/08/19 职场文书
诗词赏析-(浣溪沙)
2019/08/13 职场文书
Redis 异步机制
2022/05/15 Redis