-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage6-changeroom.js
60 lines (52 loc) · 1.43 KB
/
page6-changeroom.js
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
//THIS CODE WAS TAKEN AND EDITED FROM LAB 7
//LAB 7 WAS MADE BASED UPON ARMAN'S TUTORIAL
// GETS PPE IMG ELEMENTS
$('document').ready(function()
{
drag($("#gloves"));
drag($("#hat"));
drag($("#goggle"));
drag($("#mask"));
drag($("#shoe"));
drag($("#gown"));
});
selectedElement=null;
function dragMouseDown(e){
e = e || window.event;
e.preventDefault();
//get the mouse cursor position at startup:
initialX=e.clientX;
initialY=e.clientY;
$(document).mouseup(function(){removeHandlers()});
//call a function whenever the cursor move:
$(document).mousemove(function(){mymousemove()});
}
function mymousemove(e)
{
e=e || window.event;
e.preventDefault();
//calculate the new cursor position:
deltaX= initialX - e.clientX;
deltaY= initialY - e.clientY;
initialX = e.clientX;
initialY = e.clientY;
//set the elements new position:
$(selectedElement).css("top",(selectedElement.offset().top - deltaY)+"px");
$(selectedElement).css("left",(selectedElement.offset().left - deltaX)+"px");
}
function removeHandlers()
{
// stop moving when mouse button is released
$(document).unbind("mouseup");
$(document).unbind("mousemove");
}
//DRAG ELEMENT WITH THIS FUNCTION
function drag(element)
{
var deltaX =0,deltaY=0, initialX=0,initialY=0;
$(element).mousedown(function()
{
selectedElement= $(element);
dragMouseDown()
});
}