-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage1.html
129 lines (113 loc) · 3.45 KB
/
page1.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Products SPA</title>
</head>
<body>
<div id="app">
<!-- Navigation bar -->
<nav>
<ul>
<li><a href="#" onclick="showHome()">Home</a></li>
<li><a href="#" onclick="showProducts()">Products</a></li>
</ul>
</nav>
<!-- Main content area -->
<div id="main-content">
<!-- Home view -->
<div id="home-view" class="view">
<h1>Welcome to our SPA!</h1>
<p>This is a single-page application demonstrating dynamic product rendering.</p>
</div>
<!-- Products view -->
<div id="products-view" class="view">
<h1>Our Products</h1>
<div id="product-list">
<!-- Product items will be dynamically inserted here -->
</div>
</div>
</div>
</div>
<script>
// Sample dynamic products array
const products = [
{ name: "Jersey", price: "R299", description: "Designed for outdoors" },
{ name: "Football", price: "R199", description: "Official size and weight" },
{ name: "Basketball", price: "R149", description: "Indoor/outdoor composite leather" },
{ name: "Running Shoes", price: "R399", description: "Breathable and lightweight" },
{ name: "Tennis Racket", price: "R249", description: "Graphite construction for power and control" },
{ name: "Golf Clubs", price: "R799", description: "Complete set with bag included" },
{ name: "Swimming Goggles", price: "R79", description: "Anti-fog and UV protection" }
];
// Function to render products
function renderProducts() {
const productList = document.getElementById("product-list");
productList.innerHTML = ""; // Clear previous content
products.forEach(product => {
const productItem = document.createElement("div");
productItem.classList.add("product-item");
productItem.innerHTML = `
<h2>${product.name}</h2>
<p>Price: ${product.price}</p>
<p>Description: ${product.description}</p>
`;
productList.appendChild(productItem);
});
}
// Function to show home view
function showHome() {
document.getElementById("home-view").style.display = "block";
document.getElementById("products-view").style.display = "none";
}
// Function to show products view
function showProducts() {
document.getElementById("home-view").style.display = "none";
document.getElementById("products-view").style.display = "block";
document.getElementById("products-view").classList.add("slide-in"); // Apply slide-in animation
renderProducts();
}
// Initially show home view
showHome();
</script>
<style>
body {
font-family: Arial, sans-serif;
}
nav ul {
list-style-type: none;
padding: 0;
}
nav ul li {
display: inline;
margin-right: 20px;
}
.view {
display: none;
}
.product-item {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}
.product-item h2 {
margin-top: 0;
}
/* Slide-in animation */
@keyframes slideIn {
from {
transform: translateX(100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
.slide-in {
animation: slideIn 0.5s forwards;
}
</style>
</body>
</html>