-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes
209 lines (174 loc) · 5.14 KB
/
notes
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html>
<head>
<meta name="viewport"
content="width=device-width,
initial-scale=1.0,
user-scalable=no" />
<title>drag</title>
<style>
#container {
width: 100%;
height: 400px;
background-color: #333;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
border-radius: 7px;
touch-action: none;
}
#item {
width: 100px;
height: 100px;
background-color: rgb(245, 230, 99);
border: 10px solid rgba(136, 136, 136, .5);
border-radius: 50%;
touch-action: none;
user-select: none;
}
#item:active {
background-color: rgba(168, 218, 220, 1.00);
}
#item:hover {
cursor: pointer;
border-width: 20px;
}
</style>
</head>
<body>
<div id="outerContainer">
<div id="container">
<div id="item">
</div>
</div>
</div>
<script>
</script>
</body>
</html>
<!-- working code for moving selected element -->
class CardElementsOffsets {
constructor(name, Xoffset = 0, Yoffset = 0){
this.name = name;
this.Xoffset = Xoffset;
this.Yoffset = Yoffset;
CardElementsOffsets.all.push(this)
}
}
CardElementsOffsets.all = [];
let h1 = document.createElement('h1')
document.body.appendChild(h1)
h1.innerText = "ESDEATH"
let counter = 0;
let cardDiv = document.createElement('div')
cardDiv.style = "border: 5px solid black; width: 100%; height: 400px; background-color: #333; overflow: hidden; border-radius: 7px; touch-action: none;"
document.body.appendChild(cardDiv)
h1.addEventListener('click', () => { let img = document.createElement('img')
// img.src="https://static.wikia.nocookie.net/villains/images/9/97/TheEsdeath.png/revision/latest/scale-to-width-down/991?cb=20181205150807"
img.src="http://assets.stickpng.com/images/580b57fcd9996e24bc43c3db.png"
img.style = "width auto; height: 150px;"
img.id = `esdeath_${counter}`
// setTranslate(13,78,img)
//
counter += 1;
cardDiv.appendChild(img)
let getofst = img.getBoundingClientRect()
let ofst = solve(getofst.left, getofst.top)
setTranslate(ofst.x,ofst.y,img)
let cardElem = new CardElementsOffsets(img.id)
cardElem.Xoffset = ofst.x
cardElem.Yoffset = ofst.y
})
let dragItem;
let active = false;
let currentX;
let currentY;
let initialX;
let initialY;
let xOffset;
let yOffset;
let target;
//cardDiv.addEventListener('mousedown', (e) => (dragItem = document.getElementById(e.target.id)))
cardDiv.addEventListener("mousedown", dragStart, false);
cardDiv.addEventListener("mouseup", dragEnd, false);
cardDiv.addEventListener("mousemove", drag, false);
function dragStart(e) {
<!-- until card div -->
dragItem = document.getElementById(e.target.id)
<!-- -->
dragItem.style.position = ''
target = CardElementsOffsets.all.find(element => element.name === e.target.id)
active = true;
initialX = e.clientX - target.Xoffset;
initialY = e.clientY - target.Yoffset;
}
function drag(e) {
if (active) {
e.preventDefault();
currentX = e.clientX - initialX;
currentY = e.clientY - initialY;
target.Xoffset = currentX;
target.Yoffset = currentY;
setTranslate(currentX, currentY, dragItem);
}
}
function setTranslate(xPos, yPos, el) {
el.style.transform = "translate(" + xPos + "px, " + yPos + "px)";
}
function dragEnd(e) {
active = false;
}
function getOffset(el) {
const rect = el.getBoundingClientRect();
return {
left: rect.left + window.scrollX,
top: rect.top + window.scrollY
};
}
function solve (xNum, yNum) {
let x = (13 - xNum)
let y = (78.109375 - yNum)
return {x: x, y: y}
}
<!-- Error with postgres and Active record -->
ActiveRecord::NoDatabaseError: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "spooky_season_development" does not exist
<!-- join migration -->
rails g migration CreatePosition name:string x_position:integer y_position:integer card:references element:references
<!-- send fetch to card create function -->
const createCard = () => {
let formData = {
name: input.value,
};
let configObj = {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify(formData)
};
return fetch("http://127.0.0.1:3000/cards", configObj)
.then(function(response) {
return response.json();
})
.then(function(object) {
console.log(object);
})
.catch(function(error) {
alert("Bad things! Ragnarők!");
console.log(error.message);
});
}
<!-- Offset Class -->
class CardElementsOffsets {
constructor(name, Xoffset = 0, Yoffset = 0){
this.name = name;
this.Xoffset = Xoffset;
this.Yoffset = Yoffset;
CardElementsOffsets.all.push(this)
}
}
CardElementsOffsets.all = [];
let target;
document.addEventListener('click', (e) => { target = ep.find(element => element.name === e.target.id )})