JS code to achieve the effect of color flashing hyperlinks

Source: Internet
Author: User
Tags setinterval tagname tostring
Js| Links | flashing

Code: (Add the following code to the
var rate = 30;
var object;
var act = 0;
var elmh = 0;
var ElmS = 128;
var elmv = 255;
var clrorg;
var Timerid;

if (Navigator.appName.indexOf ("Microsoft", 0)!=-1 && parseint (navigator.appversion) >= 4) {
Browser = true;
} else {
Browser = false;
}


function Dorainbow ()
{
if (Browser && Act!= 1) {
act = 1;
object = Event.srcelement;
clrorg = Object.style.color;
Timerid = SetInterval ("ChangeColor ()", 100);
}
}
function Stoprainbow ()
{
if (Browser && Act!= 0) {
Object.style.color = clrorg;
Clearinterval (Timerid);
act = 0;
}
}
function Dorainbowanchor ()
{
if (Browser && Act!= 1) {
object = Event.srcelement;
while (object.tagname!= ' A ' && object.tagname!= ' body ') {
object = Object.parentelement;
if (Object.tagname = = ' A ' | | object.tagname = = ' body ')
Break
}
if (Object.tagname = = ' A ' && object.href!= ') {
act = 1;
clrorg = Object.style.color;
Timerid = SetInterval ("ChangeColor ()", 100);
}
}
}
function Stoprainbowanchor ()
{
if (Browser && Act!= 0) {
if (Object.tagname = = ' A ') {
Object.style.color = clrorg;
Clearinterval (Timerid);
act = 0;
}
}
}
function ChangeColor ()
{
Object.style.color = Makecolor ();
}
function Makecolor ()
{
if (ElmS = = 0) {
ELMR = ELMV; ELMG = ELMV; ELMB = ELMV;
}
else {
T1 = ELMV;
T2 = (255-elms) * elmv/255;
T3 = elmh% 60;
T3 = (t1-t2) * T3/60;

if (ELMH < 60) {
ELMR = T1; ELMB = T2; ELMG = t2 + t3;
}
else if (ELMH < 120) {
ELMG = T1; ELMB = T2; ELMR = T1-T3;
}
else if (ELMH < 180) {
ELMG = T1; ELMR = T2; ELMB = t2 + t3;
}
else if (ELMH < 240) {
ELMB = T1; ELMR = T2; ELMG = T1-T3;
}
else if (ELMH < 300) {
ELMB = T1; ELMG = T2; ELMR = t2 + t3;
}
else if (ELMH < 360) {
ELMR = T1; ELMG = T2; ELMB = T1-T3;
}
else {
ELMR = 0; ELMG = 0; ELMB = 0;
}
}
ELMR = Math.floor (ELMR);
ELMG = Math.floor (ELMG);
ELMB = Math.floor (ELMB);
Clrrgb = ' # ' + elmr.tostring + elmg.tostring + elmb.tostring (16);
ELMH = elmh + rate;
if (ELMH >= 360)
ELMH = 0;
return CLRRGB;
}
Document.onmouseover = Dorainbowanchor;
Document.onmouseout = Stoprainbowanchor;
</script> then do a connection in the body domain to see the effect of any!

<pead><script language= "javascript" >var rate = 30;var Object;var act = 0;var elmh = 0;var ElmS = 128;var ElmV = 255;var Clrorg;var timerid;if (navigator.appName.indexOf ("Microsoft", 0)!=-1 && parseint ( navigator.appversion) >= 4) {Browser = true;} else {Browser = false;} function Dorainbow () {if (Browser && Act!= 1) {act = 1;object = event.srcelement;clrorg = Object.style.color; Timerid = SetInterval ("ChangeColor ()", 100);}} function Stoprainbow () {if (Browser && Act!= 0) {Object.style.color = Clrorg;clearinterval (timerid); act = 0;}} function Dorainbowanchor () {if (Browser && Act!= 1) {object = Event.srcelement;while (object.tagname!= ' A ' && Amp Object.tagname!= ' body ') {object = object.parentelement;if (Object.tagname = = ' A ' | | | object.tagname = ' body ') break;} if (Object.tagname = = ' A ' && object.href!= ') {act = 1;clrorg = Object.style.color; Timerid = SetInterval ("ChangeColor ()", 100);}}} function Stoprainbowanchor () {if (Browser && Act!= 0 {if (object.tagname = = ' A ') {Object.style.color = Clrorg;clearinterval (timerid); act = 0;}}} function ChangeColor () {object.style.color = Makecolor ();} function Makecolor () {if (ElmS = 0) {elmr = ELMV; elmg = elmv; elmb = ELMV;} else {T1 = Elmv;t2 = (255-elms) * elmv/255;t3 = elmh% 60;t3 = (t1-t2) * T3/60;IF (ELMH <) {ELMR = T1; elmb = T2; ELMG = t2 + t3;} else if (Elmh <) {ELMG = t1; elmb = t2; elmr = t1-t3;} else if (ELMH < 180) {ELMG = t1; elmr = t2; elmb = t2 + t3;} else if (Elmh <) {ELMB = t1; elmr = t2; elmg = t1-t3;} else if (Elmh <) {ELMB = t1; elmg = t2; elmr = t2 + t3;} else if (ELMH < 360) {ELMR = t1; elmg = t2; elmb = t1-t3;} else {elmr = 0; elmg = 0; elmb = 0;}} ELMR = Math.floor (ELMR); ELMG = Math.floor (ELMG); ELMB = Math.floor (ELMB); clrrgb = ' # ' + elmr.tostring (+) + elmg.tostring (1 6) + elmb.tostring; elmh = elmh + rate;if (ELMH >= 360) elmh = 0;return Clrrgb;} Document.onmouseover = Dorainbowanchor;document.onmouSeout = Stoprainbowanchor;</script></pead><body><a href= "http://www.webjx.com" > Web Teaching Network </ A></body>

[Ctrl + A ALL SELECT hint: You can modify some of the code, and then 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.