folder names
BIN
3-terrarium/solution/images/plant1.png
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
3-terrarium/solution/images/plant10.png
Normal file
After Width: | Height: | Size: 127 KiB |
BIN
3-terrarium/solution/images/plant11.png
Normal file
After Width: | Height: | Size: 147 KiB |
BIN
3-terrarium/solution/images/plant12.png
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
3-terrarium/solution/images/plant13.png
Normal file
After Width: | Height: | Size: 170 KiB |
BIN
3-terrarium/solution/images/plant14.png
Normal file
After Width: | Height: | Size: 168 KiB |
BIN
3-terrarium/solution/images/plant2.png
Normal file
After Width: | Height: | Size: 109 KiB |
BIN
3-terrarium/solution/images/plant3.png
Normal file
After Width: | Height: | Size: 83 KiB |
BIN
3-terrarium/solution/images/plant4.png
Normal file
After Width: | Height: | Size: 97 KiB |
BIN
3-terrarium/solution/images/plant5.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
3-terrarium/solution/images/plant6.png
Normal file
After Width: | Height: | Size: 75 KiB |
BIN
3-terrarium/solution/images/plant7.png
Normal file
After Width: | Height: | Size: 126 KiB |
BIN
3-terrarium/solution/images/plant8.png
Normal file
After Width: | Height: | Size: 175 KiB |
BIN
3-terrarium/solution/images/plant9.png
Normal file
After Width: | Height: | Size: 122 KiB |
76
3-terrarium/solution/index.html
Normal file
@@ -0,0 +1,76 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Welcome to my Virtual Terrarium</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<!-- import the webpage's stylesheet -->
|
||||
<link rel="stylesheet" href="./style.css" />
|
||||
<!-- import the webpage's JavaScript file -->
|
||||
<script src="./script.js" defer></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="page">
|
||||
<h1>My Terrarium</h1>
|
||||
|
||||
<div id="left-container" class="container">
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant1" src="./images/plant1.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant2" src="./images/plant2.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant3" src="./images/plant3.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant4" src="./images/plant4.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant5" src="./images/plant5.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant6" src="./images/plant6.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant7" src="./images/plant7.png" />
|
||||
</div>
|
||||
</div>
|
||||
<div id="right-container" class="container">
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant8" src="./images/plant8.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant9" src="./images/plant9.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant10" src="./images/plant10.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant11" src="./images/plant11.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant12" src="./images/plant12.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant13" src="./images/plant13.png" />
|
||||
</div>
|
||||
<div class="plant-holder">
|
||||
<img class="plant" alt="plant" id="plant14" src="./images/plant14.png" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="terrarium">
|
||||
<div class="jar-top"></div>
|
||||
<div class="jar-walls">
|
||||
<div class="jar-glossy-long"></div>
|
||||
<div class="jar-glossy-short"></div>
|
||||
</div>
|
||||
<div class="dirt"></div>
|
||||
<div class="jar-bottom"></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
64
3-terrarium/solution/script.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/*The solution to draggable elements was inspired by w3schools solution on creating a [Draggable HTML Element](https://www.w3schools.com/howto/howto_js_draggable.asp).*/
|
||||
|
||||
dragElement(document.getElementById('plant1'));
|
||||
dragElement(document.getElementById('plant2'));
|
||||
dragElement(document.getElementById('plant3'));
|
||||
dragElement(document.getElementById('plant4'));
|
||||
dragElement(document.getElementById('plant5'));
|
||||
dragElement(document.getElementById('plant6'));
|
||||
dragElement(document.getElementById('plant7'));
|
||||
dragElement(document.getElementById('plant8'));
|
||||
dragElement(document.getElementById('plant9'));
|
||||
dragElement(document.getElementById('plant10'));
|
||||
dragElement(document.getElementById('plant11'));
|
||||
dragElement(document.getElementById('plant12'));
|
||||
dragElement(document.getElementById('plant13'));
|
||||
dragElement(document.getElementById('plant14'));
|
||||
|
||||
/*"A closure is the combination of a function bundled together (enclosed)
|
||||
with references to its surrounding state (the lexical environment).
|
||||
In other words, a closure gives you access to an outer function’s scope
|
||||
from an inner function." Create a closure so that you can track the dragged element*/
|
||||
|
||||
function dragElement(terrariumElement) {
|
||||
//set 4 positions for positioning on the screen
|
||||
let pos1 = 0,
|
||||
pos2 = 0,
|
||||
pos3 = 0,
|
||||
pos4 = 0;
|
||||
terrariumElement.onpointerdown = pointerDrag;
|
||||
|
||||
function pointerDrag(e) {
|
||||
e.preventDefault();
|
||||
console.log(e);
|
||||
// get the initial mouse cursor position for pos3 and pos4
|
||||
pos3 = e.clientX;
|
||||
pos4 = e.clientY;
|
||||
// when the mouse moves, start the drag
|
||||
document.onpointermove = elementDrag;
|
||||
// when the mouse is lifted, stop the drag
|
||||
document.onpointerup = stopElementDrag;
|
||||
}
|
||||
|
||||
function elementDrag(e) {
|
||||
// calculate the new cursor position
|
||||
// pos1 = where the Xmouse WAS - where it IS
|
||||
pos1 = pos3 - e.clientX;
|
||||
// pos2 = where the Ymouse WAS - where it IS
|
||||
pos2 = pos4 - e.clientY;
|
||||
//reset pos3 to current location of Xmouse
|
||||
pos3 = e.clientX;
|
||||
//reset pos4 to current location of Ymouse
|
||||
pos4 = e.clientY;
|
||||
console.log(pos1, pos2, pos3, pos4);
|
||||
// set the element's new position:
|
||||
terrariumElement.style.top = terrariumElement.offsetTop - pos2 + 'px';
|
||||
terrariumElement.style.left = terrariumElement.offsetLeft - pos1 + 'px';
|
||||
}
|
||||
|
||||
function stopElementDrag() {
|
||||
// stop calculating when mouse is released
|
||||
document.onpointerup = null;
|
||||
document.onpointermove = null;
|
||||
}
|
||||
}
|
105
3-terrarium/solution/style.css
Normal file
@@ -0,0 +1,105 @@
|
||||
body {
|
||||
font-family: helvetica, arial, sans-serif;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #3a241d;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#left-container {
|
||||
left: 0px;
|
||||
}
|
||||
|
||||
#right-container {
|
||||
right: 0px;
|
||||
}
|
||||
|
||||
.container {
|
||||
background-color: #eee;
|
||||
width: 15%;
|
||||
top: 0px;
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.plant-holder {
|
||||
position: relative;
|
||||
height: 13%;
|
||||
left: -10px;
|
||||
}
|
||||
|
||||
.plant {
|
||||
position: absolute;
|
||||
max-width: 150%;
|
||||
max-height: 150%;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
/*https://codepen.io/Rotarepmi/pen/rjpNZY*/
|
||||
|
||||
.jar-walls {
|
||||
height: 80%;
|
||||
width: 60%;
|
||||
background: #d1e1df;
|
||||
border-radius: 10%;
|
||||
position: absolute;
|
||||
bottom: 0.5%;
|
||||
left: 20%;
|
||||
opacity: 0.5;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.jar-top {
|
||||
width: 50%;
|
||||
height: 5%;
|
||||
background: #d1e1df;
|
||||
position: absolute;
|
||||
bottom: 80.5%;
|
||||
left: 25%;
|
||||
opacity: 0.7;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.jar-bottom {
|
||||
width: 50%;
|
||||
height: 1%;
|
||||
background: #d1e1df;
|
||||
position: absolute;
|
||||
bottom: 0%;
|
||||
left: 25%;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.dirt {
|
||||
width: 58%;
|
||||
height: 5%;
|
||||
background: #3a241d;
|
||||
position: absolute;
|
||||
border-radius: 0 0 4rem 4rem;
|
||||
bottom: 1%;
|
||||
left: 21%;
|
||||
opacity: 0.7;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.jar-glossy-long {
|
||||
width: 3%;
|
||||
height: 20%;
|
||||
border-radius: 2rem;
|
||||
background: #ddfbff;
|
||||
position: absolute;
|
||||
bottom: 20%;
|
||||
left: 5%;
|
||||
}
|
||||
|
||||
.jar-glossy-short {
|
||||
width: 3%;
|
||||
height: 5%;
|
||||
border-radius: 2rem;
|
||||
background: #ddfbff;
|
||||
position: absolute;
|
||||
bottom: 45%;
|
||||
left: 5%;
|
||||
}
|