CSS+Js遮罩效果的TAB及焦点图片切换(推荐) 时间:2020-05-12 人气:0 Js遮罩效果的TAB及图片切换 <script language="javascript"> var $ = function (d){return document.getElementById( d );}; var isIE = (document.all) ? true : false; var Bind = function (obj,fun,arr){return function() {arr || (arr = arguments);return fun.apply(obj,arr);}};//绑定 var Tween = function(t,b,c,d){return c*thttps://img.qb5200.com/download-x/d + b;};//缓冲函数 function addEventHandler(oTarget, sEventType, fnHandler) {if (oTarget.addEventListener) {oTarget.addEventListener(sEventType, fnHandler, false);} else if (oTarget.attachEvent) {oTarget.attachEvent("on" + sEventType, fnHandler);} else {oTarget["on" + sEventType] = fnHandler; } };//事件监听 function removeEventHandler(oTarget, sEventType, fnHandler) { if (oTarget.removeEventListener) { oTarget.removeEventListener(sEventType, fnHandler, false); } else if (oTarget.detachEvent) { oTarget.detachEvent("on" + sEventType, fnHandler); } else { oTarget["on" + sEventType] = null; } };//移除监听 var Timer = {};//Timer Timer.add = function (fn){return new this.fn(fn)}; Timer.fn = function (fn){ var timer; this.play = function (speed,only){ speed || ( speed = 10 ); if(only)timer = window.setTimeout(fn,speed); else timer = window.setInterval(fn,speed); }; this.stop = function (){clearTimeout(timer);clearInterval(timer)}; }; //Mask 遮罩动画 var Mask = function (){ this.fl = Timer.add(Bind(this,this.fn)); this.from_num = 0; this.speed = 50;//动画速度,越大越慢 }; Mask.prototype.ready = function (ele,pos){ if(this.ele)this.set(this.maxWidth,this.maxHeight); this.ele = ele; this.maxWidth = this.ele.offsetWidth; this.maxHeight = this.ele.offsetHeight; this.ele.style.position = "absolute"; this.from_num = 0; if(!pos){ var x = ["left","center","right",""][parseInt(4*Math.random())], y = ["top","center","bottom",""][parseInt(4*Math.random())]; if(x == "" && y == "")x = "left";//避免同时为"" this.position = [x,y]; }else{ this.position = pos; } this.set(0,0); this.fl.stop(); }; Mask.prototype.start = function (){this.fl.play();}; Mask.prototype.stop = function (){this.fl.stop();}; Mask.prototype.set = function (width,height){//设置遮罩的矩形,用于定位遮罩的变换方向 var t,r,b,l; switch(this.position[0]){ case "left" : l = 0; r = width; break; case "center" : l = (this.maxWidth - width)/2; r = (this.maxWidth + width)/2; break; case "right" : l = this.maxWidth - width; r = this.maxWidth; break; default: l = 0; r = this.maxWidth; } switch(this.position[1]){ case "top" : t = 0; b = height; break; case "center" : t = (this.maxHeight - height)/2; b = (this.maxHeight + height)/2; break; case "bottom" : t = this.maxHeight - height; b = this.maxHeight; break; default : t = 0; b = this.maxHeight; break; } this.ele.style.clip = "rect(" + t + "px," + r + "px," + b + "px," + l + "px)" ; }; Mask.prototype.fn = function (){ var w,h; this.from_num ++ ; if(this.from_num<=this.speed){ w = Tween(this.from_num,0,this.maxWidth,this.speed); h = Tween(this.from_num,0,this.maxHeight,this.speed); this.set(w,h); }else{ this.fl.stop(); //this.start();//若不需要重复动画,把这句注释,上句不注释 } }; function ImgFlash(box){ this.box = box.getElementsByTagName("dl"); this.ge = 4;//切换间隔秒数 this.menu = []; this.mask = new Mask();//加载遮罩动画,不设置参数 即 随机效果 this.zIndex = this.box.length; var _div = document.createElement('div'); this.dang = 0; for(i=0;i1){ var A = _nav.getElementsByTagName("A")[0]; addEventHandler(A,type,Bind(this,fun,[A])); } if(_nav.nodeType == 1)_nav.getElementsByTagName("UL")[0].style.zIndex = nav.length-i; } function fun(ele){ var li = ele.parentNode; var ul = li.getElementsByTagName("UL")[0]; this.z += 1 ul.style.zIndex = this.z; if(li.className=="d")return; li.className+=(li.className.length>0? " ": "") + "d"; this.focusEle.className=this.focusEle.className.replace(/( ?|^)d\b/g, ""); this.focusEle = li; this.mask.ready(ul); this.mask.start(); }; } </script> 神秘花园 演示 人间仙境 WEB前端 VB封装一个文本文件读写类含示例Csdn网站右下角的滑出弹出提示(带关闭功能)VC++做的精美仿XP开始菜单VB+Access学生综合档案管理系统Delphi随机抽取幸运观众Access数据库版多线程的VC++高速文件搜索代码 源码下载 15个jQuery学习实例(菜单、滚动、层隐藏等)VB取汉字拼音首码(第一个字母)源码VB 多进制转换源程序杰奇网站管理系统 JIEQI CMS v1.7 短标题 Delphi版视频监控系统《Java2核心技术卷2:高级特性》第7版中文高清 PDF基于Delphi的HIS自动更新程序 v2.0C#早期开发的摄像头监控系统源码随机密码生成器VC++源程序 更短 C# 酒店管理(SQL2005)云台C#家庭视频监控系统完整版VS2008开发的C#高校宿舍管理系统C#落雪无痕IP端口扫描器VS2005火狐浏览器 Firefox v3.5 <script> new ImgFlash($("box"));//初始化 new Tab($("tab1"),"mouseover"); </script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]其实这个不只是效果,代码也是非常值得学习的。大家主要是注意页面最下面的代码<script> new ImgFlash($("box"));//初始化 new Tab($("tab1"),"mouseover"); </script> 加载全部内容