12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- var insideBox = false;
- dragElement(document.getElementById("1"));
- dragElement(document.getElementById("2"));
- dragElement(document.getElementById("3"));
- dragElement(document.getElementById("4"));
- function dragElement(elmnt) {
- // if insideBox return; Besta
- var pos1, pos2, pos3, pos4;
- elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
- elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
- if (document.getElementById(elmnt.id + "header")) {
- // if present, the header is where you move the DIV from:
- document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
- } else {
- // otherwise, move the DIV from anywhere inside the DIV:
- elmnt.onmousedown = dragMouseDown;
- }
- function dragMouseDown(e) {
- e = e || window.event;
- e.preventDefault();
- // get the mouse cursor position at startup:
- pos3 = e.clientX;
- pos4 = e.clientY;
- document.onmouseup = closeDragElement;
- // call a function whenever the cursor moves:
- document.onmousemove = elementDrag;
- }
- function elementDrag(e) {
- e = e || window.event;
- e.preventDefault();
- // calculate the new cursor position:
- pos1 = pos3 - e.clientX;
- pos2 = pos4 - e.clientY;
- pos3 = e.clientX;
- pos4 = e.clientY;
- // set the element's new position:
- elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
- elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
-
- /* if pos1 and pos2 lie within range of limits of box, insideBox = true, freeze ids 1,2,3,4 Besta man */
- }
- function closeDragElement() {
- // stop moving when mouse button is released:
- // write logic if object is in box, change captcha parameters
- document.onmouseup = null;
- document.onmousemove = null;
- }
- }
- // if insideBox {
- // document.getElementById("1").disabled = true;
- // document.getElementById("2").disabled = true;
- // document.getElementById("3").disabled = true;
- // document.getElementById("4").disabled = true;
- // }
|