Mootools插件-闪烁的标题
回想起来,我已经好久没有写点啥了,尤其是关于Mootools方面的东西,因此今天写了一个标题闪烁的插件,练练手!
简单说一下这个插件的功能:该插件可以轻松的让您的<title>标题实现闪烁效果.
注意:我所使用的mootools的core版本是1.4.1,其他的版本我并未测试,如果您有测试的话麻烦短消息告知我测试结果,谢谢!
我们先来看一下这个插件的执行效果吧!如下图:
下边是这个插件的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | /** 插件:閃爍的標題 描述:該插件可以輕鬆讓您的<title>標題實現閃爍效果 參數: tit:(必填)需要在<title>上閃爍的內容 tim:[可選]閃動頻率,多少毫秒閃動一次 delay:[可選]延遲多少毫秒停止閃動 注意: 不管是變量還是方法,只要前邊有下劃綫的均為私有 用法: a=new xTitle(); a.Start({tit:'【短消息】',tim:200,delay:6000}); /**/ var xTitle= new Class({ Implements:[Options,Events], Opt:{ tim:280, //閃動頻率,多少毫秒閃動一次 tit: '' , //要閃動的內容 delay: null , //延遲多少毫秒停止閃動 _mess: '' , //全局標示符,標記現在需要閃動的內容 _title: '' , //原始標題,即<title>標籤內的原始值 _timer1: '' , //計時器句柄1 _timer2: '' //計時器句柄2 }, initialize: function (Opt){ //初始化构造函数 this .setOptions(Opt); //設置Options if (! this .Opt.tit){ return false ;} }, _run: function (){ this .Opt._mess=( this .Opt._mess== '' ) ? this .Opt.tit : '' ; $(document).getElement( 'title' ).set( 'text' , this .Opt._mess+ ' ' + this .Opt._title); this .Opt._timer1= this ._run.delay( this .Opt.tim, this ); }, _stop: function (){ clearTimeout( this .Opt._timer1); clearTimeout( this .Opt._timer2); $(document).getElement( 'title' ).set( 'text' , this .Opt._title); return false ; }, Start: function (o){ if (!o){ return false ;} this .Opt._title=$(document).getElement( 'title' ).get( 'text' ); this .Opt.tim=(o.tim && !isNaN(o.tim)) ? o.tim.toInt() : this .Opt.tim; this .Opt.delay=(o.delay && !isNaN(o.delay)) ? o.delay.toInt() : this .Opt.delay; this .Opt.tit=(o.tit) ? o.tit : this .Opt.tit; if ( this .Opt.delay){ this .Opt._timer2=( this ._stop.delay( this .Opt.delay, this )); } this ._run(); } }); a= new xTitle(); a.Start({tit: '【短消息】' ,delay:6000}); |
这个插件的使用方法如下:
<strong> //这是最完整的用法:</strong> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <html xmlns= "http://www.w3.org/1999/xhtml" ><head> <meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" > <title>www.7di.net</title> <meta name= "generator" content= "editplus" /> <meta name= "copyright" content= "www.7di.net" /> <script type= "text/javascript" src= "@img/mootools-core-1.4.1.js" onerror= "alert('Error loading '+this.src);" ></script> </head> <body> <script language= "javascript" > a= new xTitle(); a.Start({tit: '【短消息】' ,tim:300,delay:6000}); </script> </body> </html> <strong> //不需要自定义闪烁频率的用法:</strong> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <html xmlns= "http://www.w3.org/1999/xhtml" ><head> <meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" > <title>www.7di.net</title> <meta name= "generator" content= "editplus" /> <meta name= "copyright" content= "www.7di.net" /> <script type= "text/javascript" src= "@img/mootools-core-1.4.1.js" onerror= "alert('Error loading '+this.src);" ></script> </head> <body> <script language= "javascript" > a= new xTitle(); a.Start({tit: '【短消息】' ,delay:6000}); </script> </body> </html> <strong> //也不需要自动停止闪烁的用法:</strong> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <html xmlns= "http://www.w3.org/1999/xhtml" ><head> <meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" > <title>www.7di.net</title> <meta name= "generator" content= "editplus" /> <meta name= "copyright" content= "www.7di.net" /> <script type= "text/javascript" src= "@img/mootools-core-1.4.1.js" onerror= "alert('Error loading '+this.src);" ></script> </head> <body> <script language= "javascript" > a= new xTitle(); a.Start({tit: '【短消息】' }); </script> </body> </html> |
分类:
编程
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库