[javascript] muis volgen

Pagina: 1
Acties:

  • aqua_man
  • Registratie: Januari 2002
  • Laatst online: 26-07-2023

aqua_man

one life, live it!

Topicstarter
HEAD:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
<script language="JavaScript">
<!-- Begin
function Mouse(e) {
document.pic1.width=screen.width;
document.pic1.height=1;
div1.style.top=event.clientY;
document.pic2.height=screen.height;
document.pic2.width=1;
div2.style.left=event.clientX;
}
document.onmouseover = Mouse;
document.onmousemove = Mouse;
// End -->

BODY:
code:
1
2
3
4
5
6
7
<div id="div1" style="position:absolute;">
[img]blauw.jpg[/img]
</div>

<div id="div2" style="position:absolute;">
[img]blauw.jpg[/img]
</div>

dit scriptje zou het volgende moeten doen:
het geeft 2 lijnen die elkaar precies kruisen op het punt waar je je muis houdt

maar waar ze kruisen is niet precies waar je aanwijst, maar iets eronder (in het midden van je muisaanwijzer ongeveer) wat doe ik fout?

en screen.width/screen.height is natuurlijk te breed/hoog, heb je in javascript ook zoiets als available height ofzo?

2 swim or not 2 swim, that's the question


  • RRX
  • Registratie: Mei 2000
  • Laatst online: 25-08 23:43

RRX

@life-

Op dinsdag 15 januari 2002 10:30 schreef aqua_man het volgende:

[..]
kun je niet gewoon een paar pixels naar links, en naar boven erbij op tellen?

mijn T.net systeemspecspagina


  • crisp
  • Registratie: Februari 2000
  • Laatst online: 13:11

crisp

Devver

Pixelated

Die ruimte komt door de <enter> tussen de <div> en de <img> tags.

Hier een werkend voorbeeld (ook voor als je scrollbars hebt).
Warning: layout verneukende code ahead! ;)
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<html>
<head>
<title>crosshair</title>
<script language="JavaScript">
<!-- Begin
function Mouse(e) {
  document.pic1.width=Math.max(document.body.clientWidth, document.body.scrollWidth);
  var newtop = event.clientY + document.body.scrollTop;
  if (newtop > document.body.clientHeight + document.body.scrollTop) newtop = document.body.clientHeight + document.body.scrollTop - 1;
  div1.style.pixelTop=newtop;
  document.pic2.height=Math.max(document.body.clientHeight, document.body.scrollHeight);
  var newleft = event.clientX + document.body.scrollLeft;
  if (newleft > document.body.clientWidth + document.body.scrollLeft) newleft = document.body.clientWidth + document.body.scrollLeft - 1;
  div2.style.pixelLeft=newleft;
}
document.onmouseover = Mouse;
document.onmousemove = Mouse;
// End -->
</script>
</head>
<body style="overflow: auto">
<div id="div1" style="position:absolute; left: 0px; height: 1px;">[img]"blauw.jpg"[/img]</div>
<div id="div2" style="position:absolute; top: 0px; width: 1px;">[img]"blauw.jpg"[/img]</div>
</body>
</html>

Intentionally left blank


  • aqua_man
  • Registratie: Januari 2002
  • Laatst online: 26-07-2023

aqua_man

one life, live it!

Topicstarter
t nx!

is er ook een manier om de muis in het midden van je page te zetten aan het begin?

2 swim or not 2 swim, that's the question


  • Bosmonster
  • Registratie: Juni 2001
  • Laatst online: 29-08 19:47

Bosmonster

*zucht*

nope.. :)

Verwijderd

Op dinsdag 15 januari 2002 16:20 schreef aqua_man het volgende:
t nx!

is er ook een manier om de muis in het midden van je page te zetten aan het begin?
HAHAHA, dat zou cooool zijn!!! <body onload="mouseClientX = GetRandomNumber(); mouseClientY = GetRandomNumber(); "> :D
Pagina: 1