Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This PR is the solution to the 'Terrarium' #Issue 2 #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions 2-terrarium/My-terranium/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <!--to ensure using the latest rendering mode-->>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css" />
<script src="./script.js" defer></script>
<title>Virtual Terranium</title>
</head>
<body>
<h1 style="color: red;">My Terrarium</h1>
<div id="page">
<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="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 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>

</body>
</html>

72 changes: 72 additions & 0 deletions 2-terrarium/My-terranium/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@


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'));


function dragElement(terrariumElement) {

let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
terrariumElement.onpointerdown = pointerDrag;

function pointerDrag(e) {
e.preventDefault();
pos3 = e.clientX;
pos4 = e.clientY;

document.onpointermove = elementDrag;
document.onpointerup = stopElementDrag;
console.log(initialx,initialy);

}

function elementDrag(e) {
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
terrariumElement.style.top = terrariumElement.offsetTop - pos2 + 'px';
terrariumElement.style.left = terrariumElement.offsetLeft - pos1 + 'px';
}

function stopElementDrag() {
document.onpointerup = null;
document.onpointermove = null;
}



terrariumElement.addEventListener("dblclick", (event) => {
let lightColors = [
"#FFB6C1",
"#B0E0E6",
"#98FB98",
"#FFD700",
"#E0FFFF",
"#F0E68C",
"#D3D3D3",
"#ADD8E6",
"#FFDEAD",
"#FFE4B5"
];
let randomColor = lightColors[Math.floor(Math.random() * lightColors.length)];
terrariumElement.style.border= "solid black 2px";
terrariumElement.style.maxWidth = "85%";
terrariumElement.style.background=randomColor;
});

}


113 changes: 113 additions & 0 deletions 2-terrarium/My-terranium/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
h1 {
color: blue;
}

body {
font-family: helvetica, arial, sans-serif;
}

h1 {
color: #3a241d;
text-align: center;
}

#left-container {
background-color: #eee;
width: 15%;
left: 0px;
top: 0px;
position: absolute;
height: 100%;
padding: 10px;
}

.container {
background-color: #eee;
width: 15%;
right: 0px;
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;
}

.jar-walls {
height:80%;
width:60%;
background :#d1e1df;
border-radius: 1rem;
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: 60%;
height: 5%;
background: #3a241d;
position: absolute;
border-radius: 0 0 1rem 1rem;
bottom: 1%;
left: 20%;
opacity: 0.7;
z-index: -1;
}

.jar-glossy-long {
position:relative;
top:350px;
left:30px;
height: 200px;
width:20px;
border-radius: 5px;
background-color: #f1f4f6;
}

.jar-glossy-short {
position:relative;
top:95px;
left:30px;
height: 35px;
width:20px;
background-color: #f1f4f6;
border-radius: 15px

}

Loading