-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
133 lines (105 loc) · 4.41 KB
/
app.js
File metadata and controls
133 lines (105 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const option = document.getElementById('search-select');
// const slider = document.getElementById('slider');
// const output = document.getElementById('value-output');
// const imageContainer= document.getElementById('image-container');
option.addEventListener('change',function() {
var selectedFile=this.value;
if(selectedFile){
window.location.href=selectedFile;
}
});
// const images=["box1.jpg","box2.jpg","box3.jpg","box4.jpg","box5.jpg"];
// const initialImage=images[slider.value/(100/images.length)];
// imageContainer.innerHtml=`<img src="${initialImage}" alt="Slider Image">`;
// slider.addEventListener("input", () => {
// const currImageIndex=slider.value/(100/images.length);
// const currImage=images[currImageIndex];
// imageContainer.innerHtml=`<img src="${currImage}" alt="Slider Image">`;
// const value=slider.value;
// output.textContent=value;
// });
// function changeImage(value) {
// var imageSrc="box"+value+".jpg";
// document.getElementById('displayedImage').src=imageSrc;
// }
// document.addEventListener('DOMContentLoaded',function() {
// const button=document.getElementById('toggleButton');
// button.addEventListener('click',function() {
// toggleToolbar();
// });
// function toggleToolbar(){
// var toolbar=document.getElementById("sidebar");
// if(toolbar.style.left==="0px"){
// toolbar.style.left="-250px";
// }else{
// toolbar.style.left="0px";
// }
// }
// });
// const sidebarToggle=document.getElementById("toggleButton");
// const sidebar=document.getElementById("sidebar");
// sidebarToggle.addEventListener("click",()=>{
// sidebar.classList.toggle("hidden");
// });
// const navopen = document.querySelector('button.openbtn');
// const navclose = document.querySelector('a.closebtn');
// navopen.addEventListener('click', openNav);
// navclose.addEventListener('click', closeNav);
// function openNav() {
// document.getElementById("mySidebar").style.width = "250px";
// document.getElementById("main").style.marginLeft = "250px";
// }
// function closeNav() {
// document.getElementById("mySidebar").style.width = "0";
// document.getElementById("main").style.marginLeft= "0";
// }
const navopen = document.querySelector('button.openbtn');
const navclose = document.querySelector('a.closebtn');
navopen.addEventListener('click',() =>{
document.getElementById("mySidebar").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
});
navclose.addEventListener('click', () =>{
document.getElementById("mySidebar").style.width = "0";
document.getElementById("main").style.marginLeft= "0";
});
// Sample product data (repocumelace with your actual product data)
const productsData = [
{ id: 1,image:"", name: 'Rawa', price:20,oldPrice:100 },
{ id: 2,image:"", name: 'Sooji', price:30,oldPrice:100},
{ id: 3,image:"", name: 'Atta', price:40,oldPrice:100},
{ id: 4,image:"", name: 'Rice flour',price:50,oldPrice:100},
{ id: 5,image:"", name: 'Floor', price:60,oldPrice:100},
{ id: 6,image:"", name: 'Maida', price:70,oldPrice:100},
// Add more products as needed
];
// Function to dynamically generate product cards
function generateProductCards(products) {
const productsContainer = document.getElementById('products');
products.forEach(product => {
const productCard = document.createElement('div');
productCard.classList.add('product');
productCard.innerHTML = `
<img src="${product.image}" alt="${product.name}"/>
<h2>${product.name}</h2>
<p>₹${product.price}</p>
<p1>₹${product.oldPrice}</p1>
<button class="addToCartBtn" data-product-id="${product.id}">Add to Cart</button>`;
productsContainer.appendChild(productCard);
});
}
// Function to handle adding a product to the cart (you can implement the cart logic here)
document.querySelectorAll('.addToCartBtn').forEach(button => {
button.addEventListener('click', () => {
const productId = button.dataset.productId;
addToCart(productId);
});
});
function addToCart(productId) {
// Implement your logic to add the product to the cart
console.log(`Product with ID ${productId} added to the cart.`);
}
// Generate product cards on page load
window.onload = function() {
generateProductCards(productsData);
};