faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

29 of 38 people (76%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How can I have a marquee layer scroll left/right when the mouse is over an arrow button?

Jun 13th, 2000 05:38
Martin Honnen,


Here is a code example that should work with IE4+ and NN4+:

<HTML>
<HEAD>
<STYLE>
#marquee {
  position: absolute;
  color: white;
  background-color: orange;
  font-size: 24pt;
}
</STYLE>
<SCRIPT>
var tid; 
var left;
function initLeft() {
  if (document.layers)
    left = document.marquee.left;
  else if (document.all)
    left = document.all.marquee.offsetLeft;
  else if (document.getElementById)
    left = document.getElementById('marquee').offsetLeft;
}
function moveLeft () {
  if (typeof left == 'undefined') 
    initLeft();
  left -= 1;
  if (document.layers)
    document.marquee.left = left;
  else if (document.all)
    document.all.marquee.style.pixelLeft = left;
  else if (document.getElementById)
    document.getElementById('marquee').style.left = left + 'px';
}
function moveRight () {
  if (typeof left == 'undefined') 
    initLeft();
  left += 1;
  if (document.layers)
    document.marquee.left = left;
  else if (document.all)
    document.all.marquee.style.pixelLeft = left;
  else if (document.getElementById)
    document.getElementById('marquee').style.left = left + 'px';
}
</SCRIPT>
</HEAD>
<BODY>
<A HREF="javascript: void 0"
   ONMOUSEOVER="tid = setInterval('moveLeft()', 20)"
   ONMOUSEOUT="clearInterval(tid);"
>
&lt;-
</A>
|
<A HREF="javascript: void 0"
   ONMOUSEOVER="tid = setInterval('moveRight()', 20)"
   ONMOUSEOUT="clearInterval(tid);"
>
-&gt;
</A>
<BR>
<SPAN ID="marquee">
JavaScript.FAQTs.com
</SPAN>
</BODY>
</HTML>