let openShopping = document.querySelector('.shopping');
let closeShopping = document.querySelector('.closeShopping');
let list = document.querySelector('.list');
let listCard = document.querySelector('.listCard');
let body = document.querySelector('body');
let total = document.querySelector('.total');
let quantity = document.querySelector('.quantity');
openShopping.addEventListener('click', () => {
body.classList.add('active');
})
closeShopping.addEventListener('click', () => {
body.classList.remove('active');
})
let products = [{
id: 1,
name: 'Bear My Teeth',
image: 'Bare my teeth._20240226193326.png',
price: 80.25
},
{
id: 2,
name: 'Krampus',
image: 'krampus door project.jpg',
price: 109.88
},
{
id: 3,
name: 'Pix',
image: 'Untitled57_20240119222533.png',
price: 60.45
}
];
let listCards = [];
function initApp() {
products.forEach((value, key) => {
let newDiv = document.createElement('div');
newDiv.classList.add('item');
newDiv.innerHTML = `
<img src="image/${value.image}">
<div class="title">${value.name}</div>
<div class="price">${value.price.toLocaleString()}</div>
<button onclick="addToCard(${key})">Add To Cart</button>`;
list.appendChild(newDiv);
})
}
initApp();
function addToCard(key) {
if (listCards[key] == null) {
// copy product form list to list card
listCards[key] = JSON.parse(JSON.stringify(products[key]));
listCards[key].quantity = 1;
}
reloadCard();
}
function reloadCard() {
listCard.innerHTML = '';
let count = 0;
let totalPrice = 0;
listCards.forEach((value, key) => {
totalPrice = totalPrice + value.price;
count = count + value.quantity;
if (value != null) {
let newDiv = document.createElement('li');
newDiv.innerHTML = `
<div><img src="image/${value.image}"/></div>
<div>${value.name}</div>
<div>${value.price.toLocaleString()}</div>
<div>
<button onclick="changeQuantity(${key}, ${value.quantity - 1})">-</button>
<div class="count">${value.quantity}</div>
<button onclick="changeQuantity(${key}, ${value.quantity + 1})">+</button>
</div>`;
listCard.appendChild(newDiv);
}
})
total.innerText = totalPrice.toLocaleString();
quantity.innerText = count;
}
function changeQuantity(key, quantity) {
if (quantity == 0) {
delete listCards[key];
} else {
listCards[key].quantity = quantity;
listCards[key].price = quantity * products[key].price;
}
reloadCard();
}
h1 {
font-size: 150px;
margin-top: 100px;
margin-bottom: 5px;
/* text-shadow: 0 0 5px #f562ff, 0 0 15px #f562ff, 0 0 25px #f562ff,
0 0 20px #f562ff, 0 0 30px #890092, 0 0 80px #890092, 0 0 80px #890092;
color: #fccaff; */
text-shadow: 0 0 5px #ff0000, 0 0 15px #ff0000, 0 0 20px #ff0000, 0 0 40px #ff0000, 0 0 60px #ff0000, 0 0 10px #800000, 0 0 98px #ff0000;
color: #280000;
font-family: 'Guttural';
text-align: center;
justify-content: center;
align-items: center;
display: flex;
animation: blink 9s infinite;
-webkit-animation: blink 9s infinite;
}
h2 {
font-size: 80px;
margin-top: 18px;
}
h3 {
font-size: 30px;
}
h6 {
font-size: 20px;
}
body {
font-family: 'Glitch Goblin';
color: red;
text-align: center;
}
p {
font-size: 40px;
}
.right-elements {
text-align: right;
padding-top: 20px;
padding-right: 50px;
width: auto;
height: 50px;
margin: 0 auto;
justify-content: right;
align-items: right;
display: flex;
border-radius: 10%;
}
.cart {
padding-right: 12px;
transition: transform .1s;
}
.cart:hover {
transform: scale(1.2);
}
.user {
transition: transform .1s;
}
.user:hover {
transform: scale(1.2);
}
/*before i added new shop stuff leaving so i can go back if needbe
.product {
box-shadow: 0px 7px 10px 5px red;
border-radius: 20px;
}
.container {
display: grid;
grid-template-columns: auto auto auto auto;
gap: 25px;
}
.product img{
padding: 10px;
}
.product_desc h7{
font-size: 44px;
padding-left: 10px;
padding-right: 10px;
}
.product_desc p{
font-size: 32px;
}
*/
/*shop*/
.container {
width: 1000px;
margin: auto;
transition: 0.5s;
}
header {
display: grid;
grid-template-columns: 1fr 50px;
margin-top: 50px;
}
header .shopping {
position: relative;
text-align: right;
}
header .shopping img {
width: 40px;
}
header .shopping span {
background: maroon;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
position: absolute;
top: -5px;
left: 98%;
padding: 3px 10px;
}
.list {
display: grid;
grid-template-columns: repeat(3, 1fr);
column-gap: 20px;
row-gap: 20px;
margin-top: 50px;
}
.list .item {
text-align: center;
padding: 20px;
box-shadow: 0 50px 50px red;
border-radius: 20px;
letter-spacing: 1px;
}
.list .item img {
width: 90%;
height: 430px;
object-fit: cover;
border-radius: 16px;
}
.list .item .title {
font-weight: 600;
}
.list .item .price {
margin: 10px;
}
.list .item button {
background-color: red;
color: black;
width: 100%;
padding: 10px;
border-radius: 16px;
}
.card {
position: fixed;
top: 0;
left: 100%;
width: 500px;
background-color: black;
height: 100vh;
transition: 0.5s;
border-radius: 10px 0px 0px 10px;
}
.active .card {
left: calc(100% - 500px);
}
.active .container {
transform: translateX(-200px);
}
.card h1 {
color: red;
font-weight: 100;
margin: 0;
padding: 0 20px;
height: 80px;
display: flex;
align-items: center;
border-radius: 10px;
}
.card .checkOut {
position: absolute;
bottom: 0;
width: 100%;
display: grid;
grid-template-columns: repeat(2, 1fr);
}
.card .checkOut div {
background-color: red;
width: 100%;
height: 70px;
display: flex;
justify-content: center;
align-items: center;
font-weight: bold;
cursor: pointer;
border-radius: 0px 0px 0px 10px;
}
.card .checkOut div:nth-child(2) {
background-color: maroon;
color: black;
border-radius: 0px;
}
.listCard li {
display: grid;
grid-template-columns: 100px repeat(3, 1fr);
color: red;
row-gap: 10px;
}
.listCard li div {
display: flex;
justify-content: center;
align-items: center;
}
.listCard li img {
width: 90%;
}
.listCard li button {
background-color: Red;
border: none;
border-radius: 5px;
}
.listCard .count {
margin: 0 10px;
}
/* 3 images */
pictures1:nth-last-child(3):first-child {
offset-distance: 17%;
}
pictures1:nth-last-child(2):nth-child(2) {
offset-distance: 49%;
}
img:last-child:nth-child(3) {
offset-distance: 81%;
}
/* 4 images */
.pictures1:nth-last-child(4):first-child {
offset-distance: 10%;
}
.pictures1:nth-last-child(3):nth-child(2) {
offset-distance: 35%;
}
.pictures1:nth-last-child(2):nth-child(3) {
offset-distance: 65%;
}
.pictures1:last-child:nth-child(4) {
offset-distance: 90%;
}
/* 5 images */
.pictures1:nth-last-child(5):first-child {
offset-distance: 0%;
}
.pictures1:nth-last-child(4):nth-child(2) {
offset-distance: 25%;
}
.pictures1:nth-last-child(3):nth-child(3) {
offset-distance: 51%;
}
.pictures1:nth-last-child(2):nth-child(4) {
offset-distance: 75%;
}
.pictures1:last-child:nth-child(5) {
offset-distance: 100%;
}
/* effect for title*/
/* NAV BUTTON*/
*,
*::before,
*::after {
box-sizing: border-box;
}
@media only screen and (max-width: 600px) {
.glowing-btn {
font-size: 1em;
}
}
.common-section {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
margin: 10px 0;
}
.body-section {
margin: 0px 100px 0px 100px;
}
/*SOCIALS*/
.social-icons {
padding: 30px;
text-align: center;
}
.social-icons a {
color: red;
line-height: 30px;
font-size: 100px;
margin: 0 1px;
text-decoration: none;
}
.social-icons a i {
line-height: 30px;
font-size: 30px;
-webkit-transition: all 200ms ease-in;
-webkit-transform: scale(1);
-ms-transition: all 200ms ease-in;
-ms-transform: scale(1);
-moz-transition: all 200ms ease-in;
-moz-transform: scale(1);
transition: all 200ms ease-in;
transform: scale(1);
}
.social-icons a:hover i {
box-shadow: 0px 0px 150px #000000;
z-index: 2;
-webkit-transition: all 200ms ease-in;
-webkit-transform: scale(1.5);
-ms-transition: all 200ms ease-in;
-ms-transform: scale(1.5);
-moz-transition: all 200ms ease-in;
-moz-transform: scale(1.5);
transition: all 200ms ease-in;
transform: scale(1.5);
}
/*messaging*/
.form {
width: 300px;
height: 200px;
top: 50%;
left: 50%;
margin-left: 150px;
margin-top: 150px;
position: relative;
display: flex;
justify-content: center;
align-content: center;
}
/* Add styles to the form container */
.form-container {
margin: 40px 150px 0 150px;
padding: 10px;
background: linear-gradient(black, grey);
border-radius: 16px;
}
/* Full-width textarea */
.form-container textarea {
font-family: "Glitch Goblin";
color: red;
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
border: 2px solid red;
border-radius: 8px;
background: linear-gradient(grey, black);
resize: none;
min-height: 200px;
}
/* When the textarea gets focus, do something */
.form-container textarea:focus {
background-color: #FF0004;
outline: none;
}
/* Set a style for the submit/login button */
.form-container .btn {
font-family: "Glitch Goblin";
background-color: #FF0307;
color: black;
padding: 16px 20px;
border: none;
border-radius: 9px;
cursor: pointer;
width: 100%;
margin-bottom: 10px;
opacity: 0.8;
}
/* Add a red background color to the cancel button */
.form-container .cancel {
background-color: maroon;
}
/* Add some hover effects to buttons */
.form-container .btn:hover,
.open-button:hover {
opacity: 1;
}
.container1 {
display: flex;
justify-content: center;
align-items: center;
margin: 10vmin;
overflow: hidden;
transform: skew(5deg);
}
.container1 .card {
flex: 1;
transition: all 1s ease-in-out;
height: 75vmin;
position: relative;
}
.container1 .card .card__head {
color: black;
background: #ff0000;
padding: 0.5em;
transform: rotate(-90deg);
transform-origin: 0% 0%;
transition: all 0.5s ease-in-out;
min-width: 100%;
text-align: center;
position: absolute;
bottom: 0;
left: 0;
font-size: 1em;
white-space: nowrap;
}
.container1 .card:hover {
flex-grow: 10;
}
.container1 .card:hover img {
filter: grayscale(0);
}
.container1 .card:hover .card__head {
text-align: center;
top: calc(100% - 2em);
color: red;
background: rgba(0, 0, 0, 0.5);
font-size: 2em;
transform: rotate(0deg) skew(-5deg);
}
.container1 .card img {
width: 100%;
height: 100%;
object-fit: cover;
transition: all 1s ease-in-out;
filter: grayscale(100%);
}
.container1 .card:not(:nth-child(7)) {
margin-right: 1em;
}
<div class="right-elements">
<a href="cart.html" class="cart">
<img src="sitestyles/cart.png" width="46" height="47" alt="cart" />
</a>
<a href="profile.html" class="user">
<img src="sitestyles/profile.png" width="49" height="45" alt="profile" />
</a>
</div>
<p> Here is all the artworks I am currently selling! Check in frequently for new drops! </p>
</div>
</div>
<div class="container">
<header>
<div class="shopping">
<img src="image/cart.png" alt="">
<span class="quantity">0</span>
</div>
</header>
<div class="list"></div>
</div>
<div class="card">
<h1>Cart</h1>
<ul class="listCard"></ul>
<div class="checkOut">
<div class="total">0</div>
<div class="closeShopping">Close</div>
</div>
</div>