Given the complexity of building an entire web application, I'll guide you through creating simplified versions of each section. This will be conceptual and focus on key functionalities. For a full-scale project, each of these sections would be further developed and refined.
1. Sample JSON Data (Mock Database)
Create a file named data.json:
{
"items": [
{
"id": "1",
"name": "Treadmill Pro",
"price": "1200",
"userRating": "4.5",
"details": "A high-quality treadmill with interactive training.",
"features": ["Interactive Training", "Heart Rate Monitor"],
"images": ["treadmill.jpg"],
"videos": ["treadmill.mp4"]
},
{
"id": "2",
"name": "Dumbbell Set",
"price": "250",
"userRating": "4.8",
"details": "A complete set of durable dumbbells.",
"features": ["Rubber Coating", "Ergonomic Grip"],
"images": ["dumbbell.jpg"],
"videos": ["dumbbell.mp4"]
}
]
}
2. Basic HTML Structure
index.html - HomePage and Equipment Listing
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fitness Equipment Store</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Fitness Equipment Store</h1>
<input type="text" id="searchBar" placeholder="Search equipment...">
</header>
<main id="equipmentList">
<!-- Equipment items will be loaded here using JS -->
</main>
<script src="app.js"></script>
</body>
</html>
3. Basic CSS for Styles (style.css)
body, html {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
header {
background: #333;
color: #fff;
padding: 10px 20px;
text-align: center;
}
header input {
margin-top: 10px;
padding: 10px;
width: 80%;
}
main {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
padding: 20px;
}
.item {
border: 1px solid #ddd;
margin: 10px;
padding: 10px;
width: calc(50% - 20px);
}
.item img {
max-width: 100%;
height: auto;
}
4. JavaScript for Dynamic Content and Search (app.js)
First, link your JSON data:
// This would ideally be fetched from a server or local file
const data = {
"items": [
{
"id": "1",
"name": "Treadmill Pro",
"price": "1200",
"userRating": "4.5",
"details": "A high-quality treadmill with interactive training.",
"features": ["Interactive Training", "Heart Rate Monitor"],
"images": ["treadmill.jpg"],
"videos": ["treadmill.mp4"]
},
{
"id": "2",
"name": "Dumbbell Set",
"price": "250",
"userRating": "4.8",
"details": "A complete set of durable dumbbells.",
"features": ["Rubber Coating", "Ergonomic Grip"],
"images": ["dumbbell.jpg"],
"videos": ["dumbbell.mp4"]
}
]
};
function loadItems() {
const equipmentList = document.getElementById('equipmentList');
data.items.forEach((item) => {
const itemElement = document.createElement('div');
itemElement.className = 'item';
itemElement.innerHTML = `
<h3>${item.name}</h3>
<p>Price: $${item.price}</p>
<p>Rating: ${item.userRating} / 5</p>
<button onclick="alert('Reserved: ${item.name}')">Reserve</button>
`;
equipmentList.appendChild(itemElement);
});
}
// Search functionality
document.getElementById('searchBar').addEventListener('input', function(e) {
const searchTerm = e.target.value.toLowerCase();
const items = document.querySelectorAll('.item');
items.forEach((item) => {
const name = item.querySelector('h3').textContent.toLowerCase();
if (name.includes(searchTerm)) {
item.style.display = '';
} else {
item.style.display = 'none';
}
});
});
window.onload = loadItems;
Summary
With this foundational structure and code, you've created a minimal version of the fitness equipment store. The provided HTML, CSS, and JS code snippets illustrate how to list items dynamically, search through them, and apply basic styling for responsiveness. You can expand upon this by adding more features, refining the design, and implementing backend services for a full-fledged application.