무지개 하이퍼링크 적용

무지개 하이퍼링크 적용

정한솔 0 5935

무지개 하이퍼링크 적용 

<!--무지개 하이퍼링크-->

<script type="text/javascript">

var rEvent = 0;

var cArray = 0;

var aeventColor;

var anchorColor;

var rainbowStart;

var rainbowColor = new Array('red', 'orange', 'green', 'blue', 'purple');

function colorChange() {

  aeventColor.style.color = rainbowColor[cArray];

  (cArray < rainbowColor.length-1) ?  cArray++: cArray = 0;

}

function eventRainbow() {

  if(rEvent == 0) {

 var obj = event.srcElement;

   while(obj.tagName != 'A' && obj.tagName != 'BODY') {

  obj = obj.parentElement;

  if(obj.tagName == 'A' || obj.tagName == 'BODY')

   break;

 }

   if(obj.tagName == 'A' && obj.href != '') {

  aeventColor = obj;

  rEvent = 1;

  anchorColor = aeventColor.style.color;

  rainbowStart = setInterval('colorChange()', 400);

    }

  }

}

function stopRainbow() {

  if(rEvent) {

 if(aeventColor.tagName == 'A') {

  aeventColor.style.color = anchorColor;

  clearInterval(rainbowStart);

  cArray = 0;

  rEvent = 0;

 }

  }

}

document.onmouseover = eventRainbow;

document.onmouseout = stopRainbow;

</script>


0 Comments