Skip to content
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
75 changes: 75 additions & 0 deletions site/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const cardContainer = document.querySelector('.cardContainer');
const cardInfo = document.querySelector('.cardInfo');
const totalPrice = document.querySelector('#totalPrice');
const cardInfoTbody = cardInfo.querySelector('tbody');
const featuredItems = document.querySelector('.featuredItems');

cardContainer.addEventListener('click', ({ target }) => {
if (target.tagName === 'IMG') {
cardContainer.classList.toggle('cardContainer__active');
cardContainer.classList.toggle('cardContainer');
if (cardContainer.classList.contains('cardContainer__active')) {
cardInfo.style.display = "block";
} else {
cardInfo.style.display = "none";
}
}
});

featuredItems.addEventListener('click', ({ target }) => {
if (target.tagName === 'IMG') {
target = target.parentElement;
}
if (target.tagName === 'BUTTON' || target.tagName === 'IMG') {
let productData = target.parentElement.parentElement.nextElementSibling;
let productName = productData.querySelector('.featuredName')?.innerText;
let productPrice = parseFloat(productData.querySelector('.featuredPrice')?.innerText.replace('$', '')
);
let productId = productData.dataset.id;

let cardNode = cardInfo.querySelector(`#product${productId}`);
let currentTotalCount = Number.parseInt(cardCount.innerText);
cardCount.innerText = currentTotalCount + 1;
if (!cardNode) {
inserHTMLInCardInfo(productName, productPrice, productId);
} else {
changeCount(cardNode);
}
}
});



function inserHTMLInCardInfo(name, price, productId) {
let totalPriceNum = Number.parseFloat(totalPrice.innerText);
let count = 1;
let total = price;
const res = `
<tr id='product${productId}'>
<th scope="col">${name}</th>
<td class='productCount'>${count}</td>
<td class='productPrice'>\$${price.toFixed(2)}</td>
<td class='productTotal'>\$${total.toFixed(2)}</td>
</tr>
`;

cardInfoTbody.insertAdjacentHTML('beforeend', res);

totalPrice.innerText = (totalPriceNum + price).toFixed(2);
return;
}

function changeCount(cardNode) {
const productPrice = Number.parseFloat(cardNode.querySelector('.productPrice').innerText.replace('$', ''));
const productCount = cardNode.querySelector('.productCount');
const productTotal = cardNode.querySelector('.productTotal');

let totalPriceNum = Number.parseFloat(totalPrice.innerText);
let productCountNum = Number.parseInt(productCount.innerText) + 1;
let productTotalNum = productCountNum * productPrice;

productCount.innerText = productCountNum;
;
productTotal.innerText = `\$${productTotalNum.toFixed(2)}`;
totalPrice.innerText = (totalPriceNum + productPrice).toFixed(2);
}
65 changes: 46 additions & 19 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" integrity="sha512-HK5fgLBL+xu6dm/Ii3z4xhlSUyZgTT9tuc/hSrtw6uzJOvgRr2a9jyxxT1ely+B+xFAmJKVSTbpM/CuL7qxO8w==" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css"
integrity="sha512-HK5fgLBL+xu6dm/Ii3z4xhlSUyZgTT9tuc/hSrtw6uzJOvgRr2a9jyxxT1ely+B+xFAmJKVSTbpM/CuL7qxO8w=="
crossorigin="anonymous" />
<link rel="stylesheet" href="style.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">

</head>

<body>
Expand All @@ -20,11 +25,29 @@
<div class="rightHeader">
<img src="images/bars.png" alt="">
<img class="userIcon" src="images/user.png" alt="">

<span class="cartIconWrap">
<img class="cartIcon" src="images/cart.png" alt="">
<span>5</span>
</span>
<div class="cardContainer">
<span class="cartIconWrap">
<img class="cartIcon" src="images/cart.png" alt="">
<span id="cardCount">0</span>
<div class="cardInfo">
<table class="table">
<thead>
<tr>
<th scope="col">Наименование товара</th>
<th scope="col">Кол-во</th>
<th scope="col">Цена за шт.</th>
<th scope="col">Итого</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<p style="text-align: right;"><b>Товаров в корзине на сумму: </b><b>$</b><b
id="totalPrice">0.00</b>
</p>
</div>
</span>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -149,7 +172,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
</div>
</div>

<div class="featuredData">
<div class="featuredData" data-id="0">
<div class="featuredName">
ELLERY X M'O CAPSULE
</div>
Expand All @@ -159,7 +182,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
up with Moda Operandi.
</div>
<div class="featuredPrice">
$52.00
$128.00
</div>
</div>

Expand All @@ -177,7 +200,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
</div>
</div>

<div class="featuredData">
<div class="featuredData" data-id="1">
<div class="featuredName">
ELLERY X M'O CAPSULE
</div>
Expand All @@ -187,7 +210,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
up with Moda Operandi.
</div>
<div class="featuredPrice">
$52.00
$856.00
</div>
</div>

Expand All @@ -205,7 +228,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
</div>
</div>

<div class="featuredData">
<div class="featuredData" data-id="2">
<div class="featuredName">
ELLERY X M'O CAPSULE
</div>
Expand All @@ -215,7 +238,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
up with Moda Operandi.
</div>
<div class="featuredPrice">
$52.00
$76.00
</div>
</div>

Expand All @@ -233,7 +256,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
</div>
</div>

<div class="featuredData">
<div class="featuredData" data-id="3">
<div class="featuredName">
ELLERY X M'O CAPSULE
</div>
Expand All @@ -243,7 +266,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
up with Moda Operandi.
</div>
<div class="featuredPrice">
$52.00
$46.00
</div>
</div>

Expand All @@ -261,7 +284,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
</div>
</div>

<div class="featuredData">
<div class="featuredData" data-id="4">
<div class="featuredName">
ELLERY X M'O CAPSULE
</div>
Expand All @@ -271,7 +294,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
up with Moda Operandi.
</div>
<div class="featuredPrice">
$52.00
$93.00
</div>
</div>

Expand All @@ -288,7 +311,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
</div>
</div>

<div class="featuredData">
<div class="featuredData" data-id="5">
<div class="featuredName">
ELLERY X M'O CAPSULE
</div>
Expand All @@ -298,7 +321,7 @@ <h2 class="featuredHeader">Fetured Items</h2>
up with Moda Operandi.
</div>
<div class="featuredPrice">
$52.00
$247.00
</div>
</div>

Expand Down Expand Up @@ -399,12 +422,16 @@ <h2 class="featuredHeader">Fetured Items</h2>
</a>
</div>
<div class="footerRight">
&copy; 2021 Brand All Rights Reserved.
&copy; 2021 Brand All Rights Reserved.
</div>
</div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
crossorigin="anonymous"></script>
<script src="app.js"></script>
<script src="card.js"></script>
</body>

</html>
60 changes: 57 additions & 3 deletions site/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import url("https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700;900&display=swap");

body {
margin: 0;
font-family: Lato, sans-serif;
Expand All @@ -9,6 +10,9 @@ body {
height: 74px;
padding: 18px 16px;
box-sizing: border-box;
position: sticky;
top: 0;
z-index: 100;
}

.header .container {
Expand Down Expand Up @@ -41,6 +45,7 @@ body {
}

@media (min-width: 768px) {

.userIcon,
.cartIcon {
display: inline;
Expand Down Expand Up @@ -192,12 +197,12 @@ body {
margin-left: 9px;
}

.filtersRight > div:not(:last-child) {
.filtersRight>div:not(:last-child) {
margin-right: 15px;
}

@media (min-width: 375px) {
.filtersRight > div:not(:last-child) {
.filtersRight>div:not(:last-child) {
margin-right: 24px;
}
}
Expand Down Expand Up @@ -327,7 +332,7 @@ body {
color: #6f6e6e;
}

.filterSizes > div:not(:last-child) {
.filterSizes>div:not(:last-child) {
margin-bottom: 4px;
}

Expand Down Expand Up @@ -623,16 +628,19 @@ body {
font-family: inherit;
opacity: 0.67;
}

.subscribeForm input::-moz-placeholder {
color: #222224;
font-family: inherit;
opacity: 0.67;
}

.subscribeForm input:-ms-input-placeholder {
color: #222224;
font-family: inherit;
opacity: 0.67;
}

.subscribeForm input:-moz-placeholder {
color: #222224;
font-family: inherit;
Expand Down Expand Up @@ -709,3 +717,49 @@ body {
margin-top: 40px;
}
}

.cardContainer {
display: inline;
}

.cardContainer__active {
display: inline;
box-shadow: 0 0 0 29px #9f9f9f, 0 0 0 29px #9f9f9f;

background: #9f9f9f;
}

@media (min-width: 767px) {
.cardContainer:hover {
box-shadow: 0 0 0 29px #6f6e6e, 0 0 0 29px #6f6e6e;

background: #6f6e6e;
}

.cardContainer:active {
box-shadow: 0 0 0 29px #9f9f9f, 0 0 0 29px #9f9f9f;

background: #9f9f9f;
}
}

.cardInfo {
position: absolute;
background: white;
box-sizing: border-box;
padding: 10px;
right: 0px;
top: 40px;
min-width: 500px;
display: none;
overflow-y: scroll;
max-height: 400px;
}

.featuredImgDark>button:hover {
background: #6f6e6e;
}

.featuredImgDark>button:active {
background: #636363;
}