用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 相关文章推荐
基于jquery的仿百度搜索框效果代码
Apr 11 Javascript
jquery 图片上传按比例预览插件集合
May 28 Javascript
firebug的一个有趣现象介绍
Nov 30 Javascript
关闭时刷新父窗口两种方法
May 07 Javascript
jQuery增加自定义函数的方法
Jul 18 Javascript
原生js仿jquery一些常用方法(必看篇)
Sep 20 Javascript
Vue在页面数据渲染完成之后的调用方法
Sep 11 Javascript
小程序中设置缓存过期的实现方法
Jan 14 Javascript
js实现从右往左匀速显示图片(无缝轮播)
Jun 29 Javascript
基于jquery实现彩色投票进度条代码解析
Aug 26 jQuery
vue iview 隐藏Table组件里的某一列操作
Nov 13 Javascript
vue-cli中实现响应式布局的方法
Mar 02 Vue.js
漂亮的提示信息(带箭头)
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
用php来限制每个ip每天浏览页面数量的实现思路
2015/02/24 PHP
php版微信发红包接口用法示例
2016/09/23 PHP
如何在PHP中使用数组
2020/06/09 PHP
PHP常用header头定义代码示例汇总
2020/08/29 PHP
理解JavaScript的prototype属性
2012/02/11 Javascript
JavaScript输入邮箱自动提示实例代码
2014/01/13 Javascript
JavaScript中的6种运算符总结
2014/10/16 Javascript
jQuery浏览器CSS3特写兼容实例
2015/01/19 Javascript
如何实现移动端浏览器不显示 pc 端的广告
2015/10/15 Javascript
JS原型对象的创建方法详解
2016/06/16 Javascript
Bootstrap基本组件学习笔记之导航(10)
2016/12/07 Javascript
vue2滚动条加载更多数据实现代码
2017/01/10 Javascript
详解webpack进阶之插件篇
2017/07/06 Javascript
jQuery自动或手动图片切换效果
2017/10/11 jQuery
VSCode使用之Vue工程配置eslint
2019/04/30 Javascript
使用 js 简单的实现 bind、call 、aplly代码实例
2019/09/07 Javascript
Layer.js实现表格溢出内容省略号显示,悬停显示全部的方法
2019/09/16 Javascript
简单了解JavaScript sort方法
2019/11/25 Javascript
vue单文件组件无法获取$refs的问题
2020/06/24 Javascript
基于原生js实现九宫格算法代码实例
2020/07/03 Javascript
解决vant-UI库修改样式无效的问题
2020/11/03 Javascript
浅谈DataFrame和SparkSql取值误区
2018/06/09 Python
python实现公司年会抽奖程序
2019/01/22 Python
利用python和百度地图API实现数据地图标注的方法
2019/05/13 Python
python3中关于excel追加写入格式被覆盖问题(实例代码)
2020/01/10 Python
PyCharm2019 安装和配置教程详解附激活码
2020/07/31 Python
美国流行背包品牌:JanSport(杰斯伯)
2018/03/02 全球购物
西班牙最大的在线滑板和街头服饰商店:Fillow.net
2019/04/15 全球购物
绩效管理实施方案
2014/03/19 职场文书
原料仓管员岗位职责
2014/04/12 职场文书
个人考核材料
2014/05/15 职场文书
文员试用期转正自我鉴定
2014/09/14 职场文书
领导党的群众路线教育实践活动个人对照检查材料
2014/09/23 职场文书
党的群众路线教育实践活动制度建设计划方案
2014/10/31 职场文书
2015年小学远程教育工作总结
2015/07/28 职场文书
python开发人人对战的五子棋小游戏
2022/05/02 Python