jQuery 閃動(dòng)的文字提示,仿QQ頭像閃爍閃動(dòng)提示,可以用于錯(cuò)誤提示或其他吸引用戶注意力的場(chǎng)合。
shake(ele,cls,times)
ele : jQuery Object [object] 要閃動(dòng)的元素
cls : Class Name [string] 閃動(dòng)的類
times : Number [Number] 閃動(dòng)幾次
注意,必須調(diào)用jQuery1.4.2及以上版本,否則網(wǎng)頁(yè)下角會(huì)提示錯(cuò)誤。
具體代碼如下:
<!DOCTYPE HTML> <html> <head> <title>QSL 社區(qū)閃動(dòng)提示</title> <style> *{ margin:0; padding:0;} body{ background:#fff; font-family:Arial, Helvetica, sans-serif; background:#f9f9f9; font-size:14px; color:#333;} .main{ width:600px; background:#fff; margin:0 auto; padding:20px 0; border:solid #ddd; border-width:0 1px; min-height:800px;} .box{ width:240px; height:26px; line-height:26px; background:#f0f0f0; border:1px solid #ddd; text-align:center; font-size:14px; margin:20px auto;} input.box{ width:240px; font-weight:900; color:#999; display:block; background:#fff; text-align:left;} .red{ border:1px solid #d00; background:#ffe9e8; color:#d00;} input.red{background:#ffe9e8;} #box1{ cursor:pointer;} .des{ margin:0 20px; padding:6px; line-height:20px; border:1px solid #ccc; color:#555;} </style> <script type="text/javascript" src="jquery-1.6.2.min.js?7.1.34"></script> <script> function shake(ele,cls,times){ var i = 0,t= false ,o =ele.attr("class")+" ",c ="",times=times||2; if(t) return; t= setInterval(function(){ i++; c = i%2 ? o+cls : o; ele.attr("class",c); if(i==2*times){ clearInterval(t); ele.removeClass(cls); } },200); }; $(function(){ //domready 就閃動(dòng) shake($("#box"),"red",3); //點(diǎn)擊閃動(dòng) $("#box1").bind({ click:function(){ shake($(this),"red",3); return false; } }); //通不過(guò)mail校驗(yàn)閃動(dòng) $("#mail").blur( function(){ if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test($(this).val())) { shake($(this),"red",3); } } ); }); </script> </head> <body> <p class="main"> <p class="des">閃動(dòng)提示,可以用于錯(cuò)誤提示或其他吸引用戶注意力的場(chǎng)合 <br> shake(ele,cls,times)<br> ele : jQuery Object [object] 要閃動(dòng)的元素<br> cls : Class Name [string] 閃動(dòng)的類<br> times : Number [Number] 閃動(dòng)幾次 </p> <p id="box" class="box">打開(kāi)就閃動(dòng)</p><p id="box1" class="box">點(diǎn)擊就閃動(dòng)</p> <input class="box" type="email" id="mail" placeholder="不是email地址就閃動(dòng)" /> </p> </body> </html>
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com