用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 14 Javascript
Extjs学习过程中新手容易碰到的低级错误积累
Feb 11 Javascript
Jquery Ajax学习实例5 向WebService发出请求,返回泛型集合数据的异步调用
Mar 17 Javascript
js的写法基础分析
Jan 17 Javascript
推荐4个原生javascript常用的函数
Jan 12 Javascript
javascript实现移动端上的触屏拖拽功能
Mar 04 Javascript
jQuery实现div横向拖拽排序的简单实例
Jul 13 Javascript
js变量提升深入理解
Sep 16 Javascript
详解百度百科目录导航树小插件
Jan 08 Javascript
原生javascript实现文件异步上传的实例讲解
Oct 26 Javascript
JS实现图片转换成base64的各种应用场景实例分析
Jun 22 Javascript
express 项目分层实践详解
Dec 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
阿拉伯的咖啡与水烟
2021/03/03 咖啡文化
破解.net程序(dll文件)编译和反编译方法
2013/01/31 PHP
FireFox浏览器使用Javascript上传大文件
2013/10/30 PHP
在PHP上显示JFreechart画的统计图方法
2013/11/03 PHP
在laravel-admin中列表中禁止某行编辑、删除的方法
2019/10/03 PHP
JS中Iframe之间传值及子页面与父页面应用
2013/03/11 Javascript
gridpanel动态加载数据的实例代码
2013/07/18 Javascript
jquery日历控件实现方法分享
2014/03/07 Javascript
js中通过父级进行查找定位元素
2014/06/15 Javascript
jquery中change()用法实例分析
2015/02/06 Javascript
TypeScript 学习笔记之基本类型
2015/06/19 Javascript
JavaScript检测字符串中是否含有html标签实现方法
2015/07/01 Javascript
JS使用eval()动态创建变量的方法
2016/06/03 Javascript
jQuery简单实现iframe的高度根据页面内容自适应的方法
2016/08/01 Javascript
js 动态生成json对象、时时更新json对象的方法
2016/12/02 Javascript
分享19个JavaScript 有用的简写写法
2017/07/07 Javascript
JS实现table表格内针对某列内容进行即时搜索筛选功能
2018/05/11 Javascript
angular4自定义表单控件[(ngModel)]的实现
2018/11/23 Javascript
nodejs中实现修改用户路由功能
2019/05/24 NodeJs
如何使用CSS3和JQuery easing 插件制作绚丽菜单
2019/06/18 jQuery
详解Vue3.0 + TypeScript + Vite初体验
2021/02/22 Vue.js
python多线程操作实例
2014/11/21 Python
django使用LDAP验证的方法示例
2018/12/10 Python
python交换两个变量的值方法
2019/01/12 Python
基于python实现百度语音识别和图灵对话
2020/11/02 Python
python+opencv3.4.0 实现HOG+SVM行人检测的示例代码
2021/01/28 Python
CSS3实现苹果手机解锁的字体闪亮效果示例
2021/01/05 HTML / CSS
一个精品风格的世界:Atterley
2019/05/01 全球购物
高级3D打印市场:Gambody
2019/12/26 全球购物
群众路线党员个人剖析材料
2014/10/08 职场文书
2014年社区党建工作总结
2014/11/11 职场文书
2015中秋节晚会主持词
2015/07/01 职场文书
2019年第四季度财务部门工作计划
2019/11/02 职场文书
一篇文章带你复习java知识点
2021/06/28 Java/Android
高性能跳频抗干扰宽带自组网电台
2022/02/18 无线电
服务器间如何实现文件共享
2022/05/20 Servers