Meerdere div's bewegen
Ik heb een vraag, Ik ben namelijk bezig met een scirpt zodat je meerder div's kan bewegen
Dat lukt aardig, alleen het luktmaar met 1 div, zou iemand me misschien willen helpen en zeggen hoe ik status of zo kan mee sturen zodat ik kan aangeven
dit script gebruik ik:
Code (php)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<script type="text/javascript">
this.mover = new mover;
function geklicked(divnaam) {
if(document.getElementById('clicked').style.display == 'none'){
document.getElementById('clicked').style.display = 'block';
document.onmousemove = this.mover.move;
} else {
document.onmousemove = null;
document.getElementById('clicked').style.display = 'none';
}
}
function mover() {
var divx = null;
var divy = null;
this.move = function(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
} else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft;
posy = e.clientY + document.body.scrollTop;
}
var floatdiv = document.getElementById("div1");
if (!divx) {
divx = posx - parseInt(floatdiv.style.left);
divy = posy - parseInt(floatdiv.style.top);
}
floatdiv.style.top = posy - divy;
floatdiv.style.left = posx - divx;
document.getElementById("output1div").innerHTML = floatdiv.style.left;
document.getElementById("output2div").innerHTML = floatdiv.style.top;
document.getElementById("output1").innerHTML = posy;
document.getElementById("output2").innerHTML = posx;
}
}
</script>
<div id="clicked" style="display: none;"></div>
<div id="div1" style="width:300px; top:61px; left:393px; position:absolute; cursor:pointer; background-color: #CC0000;" onClick="geklicked('div1');">
<table>
<tr>
<td>Y:</td>
<td><div id="output1">-</div></td>
<td>px</td>
</tr><tr>
<td>X:</td>
<td><div id="output2">-</div></td>
<td>PX</td>
</tr>
</table> <table>
<tr>
<td>Y:</td>
<td><div id="output1div">-</div></td>
<td>px</td>
</tr><tr>
<td>X:</td>
<td><div id="output2div">-</div></td>
<td>PX</td>
</tr>
</table>
</div>
<div id="div2" style="width:300px; top:187px; left:322px; position:absolute; cursor:pointer; background-color: #CCCCCC;" onClick="geklicked('div2');">
<table>
<tr>
<td>Y:</td>
<td><div id="output1">-</div></td>
<td>px</td>
</tr><tr>
<td>X:</td>
<td><div id="output2">-</div></td>
<td>PX</td>
</tr>
</table> <table>
<tr>
<td>Y:</td>
<td><div id="output1div">-</div></td>
<td>px</td>
</tr><tr>
<td>X:</td>
<td><div id="output2div">-</div></td>
<td>PX</td>
</tr>
</table>
</div>
<br />
this.mover = new mover;
function geklicked(divnaam) {
if(document.getElementById('clicked').style.display == 'none'){
document.getElementById('clicked').style.display = 'block';
document.onmousemove = this.mover.move;
} else {
document.onmousemove = null;
document.getElementById('clicked').style.display = 'none';
}
}
function mover() {
var divx = null;
var divy = null;
this.move = function(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
} else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft;
posy = e.clientY + document.body.scrollTop;
}
var floatdiv = document.getElementById("div1");
if (!divx) {
divx = posx - parseInt(floatdiv.style.left);
divy = posy - parseInt(floatdiv.style.top);
}
floatdiv.style.top = posy - divy;
floatdiv.style.left = posx - divx;
document.getElementById("output1div").innerHTML = floatdiv.style.left;
document.getElementById("output2div").innerHTML = floatdiv.style.top;
document.getElementById("output1").innerHTML = posy;
document.getElementById("output2").innerHTML = posx;
}
}
</script>
<div id="clicked" style="display: none;"></div>
<div id="div1" style="width:300px; top:61px; left:393px; position:absolute; cursor:pointer; background-color: #CC0000;" onClick="geklicked('div1');">
<table>
<tr>
<td>Y:</td>
<td><div id="output1">-</div></td>
<td>px</td>
</tr><tr>
<td>X:</td>
<td><div id="output2">-</div></td>
<td>PX</td>
</tr>
</table> <table>
<tr>
<td>Y:</td>
<td><div id="output1div">-</div></td>
<td>px</td>
</tr><tr>
<td>X:</td>
<td><div id="output2div">-</div></td>
<td>PX</td>
</tr>
</table>
</div>
<div id="div2" style="width:300px; top:187px; left:322px; position:absolute; cursor:pointer; background-color: #CCCCCC;" onClick="geklicked('div2');">
<table>
<tr>
<td>Y:</td>
<td><div id="output1">-</div></td>
<td>px</td>
</tr><tr>
<td>X:</td>
<td><div id="output2">-</div></td>
<td>PX</td>
</tr>
</table> <table>
<tr>
<td>Y:</td>
<td><div id="output1div">-</div></td>
<td>px</td>
</tr><tr>
<td>X:</td>
<td><div id="output2div">-</div></td>
<td>PX</td>
</tr>
</table>
</div>
<br />
alvast bedankt,
Groeten Nomis
Er zijn nog geen reacties op dit bericht.