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?

15 of 21 people (71%) answered Yes
Recently 5 of 6 people (83%) answered Yes

Entry

How can I have a horizontal and vertical line attached to the cursor?
this technique seems to make any links contained in the page to break (href, onclicks, etc.). Is the

Feb 15th, 2009 21:40
Inschi jelii, Martin Honnen, adam hellman,


The following script works with IE4+, NN4 and Mozilla M16+:
<HTML>
<HEAD>
<STYLE>
#cursor {
  position: absolute;
  visibility: hidden;
}
#cursorHor {
  position: absolute;
  background-color: blue;
  layer-background-color: blue;
  width: 100px; height: 1px;
  clip: rect(0px 100px 1px 0px);
}
#cursorVer {
  position: absolute;
  background-color: blue;
  layer-background-color: blue;
  width: 1px; height: 100px;
  clip: rect(0px 1px 100px 0px);
}
</STYLE>
<SCRIPT>
var started = false;
if (document.layers)
  document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = function (evt) {
  var cursor = 
     document.layers ? document.cursor :
     document.all ? document.all.cursor :
     document.getElementById ? document.getElementById('cursor') : null;
  if (!started) {
    if (document.layers)
      cursor.visibility = 'show';
    else 
      cursor.style.visibility = 'visible';
    started = true;
  }
  if (document.layers) {
    cursor.left = evt.pageX;
    cursor.top = evt.pageY;
  }
  else if (document.all) {
    cursor.style.pixelLeft = event.x;
    cursor.style.pixelTop = event.y;
  }
  else if (document.getElementById) {
    cursor.style.left = evt.pageX + 'px';
    cursor.style.top = evt.pageY + 'px';
  }
}  
</SCRIPT>
</HEAD>
<BODY>
<DIV ID="cursor">
<DIV ID="cursorHor"></DIV>
<DIV ID="cursorVer"></DIV>
</DIV>
</BODY>
</HEAD>
http://lahjatideoita.blogspot.com
http://ideaspara-regalar.blogspot.com
http://idearegalo1.blogspot.com
http://geschenkeidee.blogspot.com
http://darkovenapady.blogspot.com