仿百度焦点轮换兼容各种IE

来源:未知 责任编辑:责任编辑 发表时间:2014-05-20 18:33 点击:

<html>
<head>
<script type="text/javascript" >
var BdScrollImage={};BdScrollImage.Navigator=function(c,b){this.domObj=c;this.observers=[];this.curIndex=0;this.curBtn=null;var e=c.getElementsByTagName("a");this.btnObjs=[];if(b){for(var d=0,a=e.length;d<a;d++){this.btnObjs.push(e[a-1-d])}}else{for(var d=0,a=e.length;d<a;d++){this.btnObjs.push(e[d])}}};BdScrollImage.Navigator.prototype.registerEvent=function(){var a=this;(function(){function b(f){f=f||window.event;var d=f.target||f.srcElement,c=1;if(d.tagName&&d.tagName.toUpperCase()=="A"){c=d.getAttribute("index");if(c!=a.curIndex){a.notify({type:"STOP"});a.curBtn.className="navbtn";d.className="navbtn curbtn";a.curIndex=c;a.curBtn=d;a.notify({type:"SCROLL",param:a.curIndex});a.notify({type:"START"})}}}if(window.attachEvent){a.domObj.attachEvent("onclick",b)}else{a.domObj.addEventListener("click",b,false)}})()};BdScrollImage.Navigator.prototype.setCurrent=function(a){if(this.curBtn){this.curBtn.className="navbtn"}this.curIndex=a;this.curBtn=this.btnObjs[a-1];this.curBtn.className="navbtn curbtn";this.notify({type:"SCROLL",param:a})};BdScrollImage.Navigator.prototype.handleMessage=function(e){var d=e.type;switch(d){case"SCROLL":var a=this.btnObjs.length,c=this.curIndex,b=c%a+1;this.setCurrent(b);break;default:break}};BdScrollImage.Controller=function(a){this.timer=0;this.interval=a||5000;this.scrollFuncName=Math.random();this.observers=[];var b=this;window[this.scrollFuncName]=function(){b.notify({type:"SCROLL"})}};BdScrollImage.Controller.prototype.start=function(){this.timer=window.setInterval(window[this.scrollFuncName],this.interval)};BdScrollImage.Controller.prototype.stop=function(){window.clearInterval(this.timer)};BdScrollImage.Controller.prototype.handleMessage=function(a){switch(a.type){case"START":this.start(this.interval);break;case"STOP":this.stop();break;case"RESTART":this.stop();this.start(this.interval);break;default:break}};BdScrollImage.Controller.prototype.registerEvent=function(){var b=Math.random(),a=this;window[b]=function(){a.start()};if(window.attachEvent){window.attachEvent("onload",window[b])}else{window.addEventListener("load",window[b],false)}};BdScrollImage.View=function(a,b){this.domObj=a;this.dataSource=b;this.curIndex=1;this.imgLink=a.getElementsByTagName("a")[0];this.imgObj=a.getElementsByTagName("img")[0];this.observers=[]};BdScrollImage.View.prototype.handleMessage=function(d){var a=this.dataSource,c=d.type;switch(c){case"SCROLL":var b=d.param;this.imgLink.href=a[b-1]["url"];this.imgObj.src=a[b-1]["imgUrl"];this.imgLink.setAttribute("mon","ct=1&a=12&pn="+b+"&col=4");break;default:break}};BdScrollImage.View.prototype.registerEvent=function(){var a=this;(function(){function b(c){c=c||window.event;switch(c.type){case"mouseover":a.notify({type:"STOP"});return;case"mouseout":a.notify({type:"START"});return;default:return}}if(window.attachEvent){a.imgObj.attachEvent("onmouseover",b);a.imgObj.attachEvent("onmouseout",b)}else{a.imgObj.addEventListener("mouseover",b,false);a.imgObj.addEventListener("mouseout",b,false)}})()};BdScrollImage.Title=function(a,b){this.domObj=a;this.dataSource=b;this.curIndex=1;this.linkObj=a.getElementsByTagName("a")[0];this.observers=[]};BdScrollImage.Title.prototype.handleMessage=function(d){var a=this.dataSource,c=d.type;switch(c){case"SCROLL":var b=d.param;this.linkObj.href=a[b-1]["url"];this.linkObj.innerHTML=a[b-1]["title"];this.linkObj.setAttribute("mon","ct=1&a=9&pn="+b+"&col=4");break;default:break}};BdScrollImage.Title.prototype.registerEvent=function(){var a=this;(function(){function b(c){c=c||window.event;switch(c.type){case"mouseover":a.notify({type:"STOP"});return;case"mouseout":a.notify({type:"START"});return;default:return}}if(window.attachEvent){a.linkObj.attachEvent("onmouseover",b);a.linkObj.attachEvent("onmouseout",b)}else{a.linkObj.addEventListener("mouseover",b,false);a.linkObj.addEventListener("mouseout",b,false)}})()};BdScrollImage.ImageList=function(a){this.iL=a};BdScrollImage.ImageList.prototype.init=function(){var a=this.iL,c,d=new Date();window[d.getTime()]=[];if(a){for(var b=0;b<a.length;b++){window[d.getTime()][b]=new Image();window[d.getTime()][b].src=a[b]["imgUrl"]}}};function implement(a,c){for(var b in a){c[b]=a[b]}}var Observable=(function(){function a(c){if(c&&typeof c=="object"&&c.handleMessage){this.observers.push(c)}}function b(d){var e=this.observers;for(var c=0;c<e.length;c++){e[c].handleMessage(d)}}return{addObserver:a,notify:b}})();implement(Observable,BdScrollImage.Navigator.prototype);implement(Observable,BdScrollImage.View.prototype);implement(Observable,BdScrollImage.Title.prototype);implement(Observable,BdScrollImage.Controller.prototype);

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Gb2312转utf-8编码的方法(vbs+js)
  • 如何使用Ajax技术开发Web应用程序(1)
  • js跳转路径问题
  • JavaScript模仿桌面窗口
  • 用js检测两个线段是否相交
  • 运用JavaScript构建你的第一个Metro式应用程序(on Windows
  • 我知道的JavaScript -- 设计模式(桥接)应用之 – 验证器
  • 我是如何去了解jquery的(六),案例之幻灯片轮换
  • Jquery封装幻灯片效果
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1