I’m new to programming. I have a start on my website. I have created a product catalog and a shopping cart. When adding an item to the cart, a notification from the browser opens, here – тык . I would like to make the notification appear and disappear after two seconds when adding an item. I found a template on the Internet, but I don’t understand how to connect it to js – https://youx.agency/pokazyvaem-uvedomlenie-posle-dobavleniya-tovara-v-korzinu?ysclid=lx0n11f5g7532710742. Help.
html
<div class="product-card-container">
<div class="wrapper_div">
<div class="nft">
<div class='main'>
<img class='tokenImage' src="{{ url_for('static', filename='img/м1.jpg') }}" alt="Набор" />
<h2>Набор</h2>
<p class='description'>Набор изделий из мыла. Отличный подарок к Новому году.</p>
<div class='tokenInfo'>
<div class="price">
<ins>◘</ins>
<p>499 Руб</p>
<button class="btn-hover color-7" onclick="addProd('1', products)">Добавить в корзину</button>
</div>
</div>
</div>
</div>
</div>
<div class="wrapper_div">
<div class="nft">
<div class='main'>
<img class='tokenImage' src="{{ url_for('static', filename='img/м2.jpg') }}" alt="Заяц" />
<h2>Заяц</h2>
<p class='description'>Детское мыло. Цена за 1 штуку.</p>
<div class='tokenInfo'>
<div class="price">
<ins>◘</ins>
<p>179 Руб</p>
<button class="btn-hover color-7" onclick="addProd('2', products)">Добавить в корзину</button>
</div>
</div>
</div>
</div>
</div>
<div class="wrapper_div">
<div class="nft">
<div class='main'>
<img class='tokenImage' src="{{ url_for('static', filename='img/м3.jpg') }}" alt="Массажка" />
<h2>Массажка</h2>
<p class='description'>Массажное мыло для тела. Цена за 1 штуку</p>
<div class='tokenInfo'>
<div class="price">
<ins>◘</ins>
<p>179 Руб</p>
<button class="btn-hover color-7" onclick="addProd('3', products)">Добавить в корзину</button>
</div>
</div>
</div>
</div>
</div>
</div>
{% block DopScript %}
let products = new Map([
['1', { id:1, name: 'Набор изделий из мыла', price: 499, image: "{{ url_for('static', filename='img/м1.jpg') }}", quantity: 0 }]
]);
function addToCookie(name, data) {
document.cookie = `${name}=${data}; ${document.cookie}`;
}
function addProd(id) {
let product = products.get(id);
if (product) {
let productData = {
id: product.id,
name: product.name,
price: product.price,
image: product.image,
quantity: product.quantity + 1 // Увеличение количества товара на 1 при добавлении
};
// Преобразуем объект товара в JSON
let productDataString = JSON.stringify(productData);
// Добавляем данные в куки
addToCookie(`product_${product.name}`, productDataString);
// Обновляем количество товара в объекте products
product.quantity++;
alert(`Товар успешно добавлен: ${product.name}, ${product.price}р`);
} else {
alert('Товар не найден');
}
}
$(document).ready(function addProd() {
setTimeout(() => {
$(document).on('click', 'a[href="#order"]', function addProd() {
$('.infotext').addClass('infotextvisible');
// Убрать уведомление через 2.5 секунды
setTimeout(function() {
$('.infotext').removeClass('infotextvisible');
}, 2500);
});
}, 1500);
});
{%endblock%}
css
.product-card-container {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
.wrapper_div{ /* Кнопка купить выравнивание */
display:flex;
flex-direction: column;
align-items:center;
}
.nft {
user-select: none;
width: 300px;
margin: 2rem;
border: 1px solid #ffffff22;
background-color: #282c34;
background: linear-gradient(0deg, rgba(40, 44, 52, 1) 0%, rgba(17, 0, 32, .5) 100%);
box-shadow: 0 7px 20px 5px #00000088;
border-radius: .7rem;
backdrop-filter: blur(7px);
-webkit-backdrop-filter: blur(7px);
overflow: hidden;
transition: .5s all;
hr {
width: 100%;
border: none;
border-bottom: 1px solid #88888855;
margin-top: 0;
}
ins {
text-decoration: none;
}
.main {
width: 90%;
padding: 1rem;
color: #c572e6;
display: flex;
flex-direction: column;
.tokenImage {
border-radius: .5rem;
max-width: 100%;
height: 250px;
object-fit: cover;
}
.tokenImage:hover{
cursor: pointer;
}
.description {
min-height: 100px;
max-height: 100px;
margin: .5rem 0;
color: #a89ec9;
}
.tokenInfo{
display: flex;
justify-content: space-between;
align-items: center;
.price{
display: flex;
align-items: center;
color: #ee83e5;
font-weight: 700;
ins{
margin-left: -.3rem;
margin-right: .5rem;
}
}
.duration{
display: flex;
align-items: center;
color: #a89ec9;
margin-right: .2rem;
ins{
margin: .5rem;
margin-bottom: .4rem;
}
}
}
.creator {
display: flex;
align-items: center;
margin-top: .2rem;
margin-bottom: -.3rem;
ins {
color: #a89ec9;
text-decoration: none;
}
.wrapper {
display: flex;
align-items: center;
border: 1px solid #ffffff22;
padding: .3rem;
margin: 0;
margin-right: .5rem;
border-radius: 100%;
box-shadow: inset 0 0 0 4px #000000aa;
img {
border-radius: 100%;
border: 1px solid #ffffff22;
width: 2rem;
height: 2rem;
object-fit: cover;
margin: 0;
}
}
}
}
::before {
position: fixed;
content: "";
box-shadow: 0 0 100px 40px #ffffff08;
top: -10%;
left: -100%;
transform: rotate(-45deg);
height: 60rem;
transition: .7s all;
}
&:hover {
border: 1px solid #ffffff44;
box-shadow: 0 7px 50px 10px #000000aa;
transform: scale(1.015);
filter: brightness(1.3);
::before {
filter: brightness(.5);
top: -100%;
left: 200%;
}
}
}
.bg {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
h1 {
font-size: 20rem;
filter: opacity(0.5);
}
}
Vladislav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.