Js script _ javascript tips for flashing an element

Source: Internet
Author: User
Some important content on the js script page with a highlighted element needs to be reminded to the customer. There are many methods available. Remind the user to pay attention to a certain area (p). You can add the frame flashing effect to the p to attract the user's attention.

<Script language = "javascript" type = "text/javascript"> <! --/* Common function library --- start --- */function $ (objString) {return document. getElementById (objString);} function addClass (elem, classString) {if (typeof (elem) = "string") var obj = document. getElementById (elem); else if (typeof (elem) = "object") var obj = elem; obj. className = obj. className + "" + classString;} function removeClass (elem, classString) {if (typeof (elem) = "string") var obj = document. getElementById (elem ); Else if (typeof (elem) = "object") var obj = elem; var classNameArray = obj. className. split (""); for (I = 0; j = classNameArray [I]; I ++) {if (j = classString) {classNameArray. splice (I, 1); I --;} obj. className = classNameArray. join ("");} function hasClass (elem, classString) {if (typeof (elem) = "string") {var obj = document. getElementById (elem);} else if (typeof (elem) = "object") {var obj = elem;} if (obj. ClassName. indexOf ("")! =-1) {var cls = obj. className. replace (// g, "|"); cls = "|" + cls + "|"; if (cls. indexOf ("|" + classString + "| ")! =-1) {return true;} else {return false} else {if (obj. className = classString) {return true;} else {return false ;}}/ * Common function libraries --- end --- */function highLight (obj) {if (obj. highlightHandel! = Null) return; obj. highlightHandel = setInterval (function () {twinkle (obj) }, 250);} function twinkle (objBox) {hasClass (objBox, "highLight ")? RemoveClass (objBox, "highLight"): addClass (objBox, "highLight");} function stopTwinkle (obj) {clearInterval (obj. highlightHandel); removeClass (obj, "highLight"); obj. removeAttribute ("highlightHandel");} // --> script <style>. box {border: 1px solid # ccc; height: 100px; width: 600px; text-align: center; line-height: 100px; background-color: # f7f7f7 }. highLight {background-color: # ffffcc; border: 1px solid # f30} </style> <p id = "demo" class = "box"> Box I </p> <input type = "button" value = "blinking" onclick = "highLight ($ ('Demo ')) "/> <input type =" button "value =" stop "onclick =" stopTwinkle ($ ('Demo ')) "/> <p id =" demo2 "class =" box "> Box II </p> <input type =" button "value =" blinking "onclick =" highLight ($ ('demo2 ')) "/> <input type =" button "value =" stop "onclick =" stopTwinkle ($ ('demo2') "/>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]


The Code contains several common functions (separated by comments), which can be replaced by methods in prototype. js. The following functions can be slightly modified and run.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.