-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
146 lines (128 loc) · 3.34 KB
/
Copy pathexample.html
File metadata and controls
146 lines (128 loc) · 3.34 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
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Car Booking</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
background-color: #fafafa;
color: #333;
margin: 20px;
text-align: center;
}
h1 {
margin-bottom: 20px;
color: #2c3e50;
}
label {
margin: 0 10px;
font-weight: 500;
}
input[type="text"],
input[type="number"] {
padding: 6px 10px;
margin-left: 5px;
border-radius: 5px;
border: 1px solid #ccc;
outline: none;
transition: border 0.2s;
}
input[type="text"]:focus,
input[type="number"]:focus {
border-color: #3498db;
}
#cars {
display: flex;
justify-content: center;
flex-wrap: wrap;
margin-top: 20px;
}
.car-card {
display: flex;
flex-direction: column;
align-items: center;
border: 2px solid #ddd;
border-radius: 12px;
padding: 15px;
margin: 10px;
width: 150px;
cursor: pointer;
background-color: #fff;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: transform 0.2s, box-shadow 0.2s;
}
.car-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 12px rgba(0, 0, 0, 0.15);
border-color: #3498db;
}
.car-card img {
width: 100%;
height: 120px;
object-fit: cover;
border-radius: 8px;
margin-bottom: 10px;
}
.car-card p {
margin: 0;
font-weight: 600;
color: #2c3e50;
}
#output {
margin-top: 25px;
font-weight: bold;
font-size: 1.1rem;
color: #e74c3c;
}
</style>
</head>
<body>
<h1>Car Booking</h1>
<label>Name: <input type="text" id="name" /></label>
<label>Age: <input type="number" id="age" /></label>
<div id="cars">
<div class="car-card">
<img src="./assets/suv.jpg" />
<p>SUV</p>
</div>
<div class="car-card">
<img src="./assets/mahindra.jpg" />
<p>Mahindra</p>
</div>
<div class="car-card">
<img src="./assets/fortuner.jpg" />
<p>Fortuner</p>
</div>
</div>
<div id="output"></div>
<script>
function bookCar(carName) {
const outputDiv = document.getElementById("output");
outputDiv.textContent = `${this.name} ${this.age} booked ${carName}`;
}
function getUserData() {
let name = document.getElementById("name").value;
let age = document.getElementById("age").value;
return {
name,
age,
};
}
document.querySelectorAll(".car-card").forEach((card) => {
card.addEventListener("click", () => {
const user = getUserData();
const carName = card.querySelector("p").textContent;
// Using call
bookCar.call(user, carName);
// Using apply
// bookCar.apply(user, [carName]);
// Using bind
// const boundBooking = bookCar.bind(user, carName);
// boundBooking();
});
});
</script>
</body>
</html>