forked from 07sumit1002/CabRental
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
137 lines (117 loc) · 4.77 KB
/
script.js
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
document
.getElementById("view-all-button")
.addEventListener("click", function () {
const testimonialsContainer = document.getElementById(
"testimonials-container"
);
document.getElementById('bookNow').addEventListener('click', function() {
alert('Booking confirmed!');
});
const newTestimonials = [
{
text: "I've used many cab services before, but this one is by far the best. Highly recommended!",
client: "- Emily",
imgSrc: "images/download.jpeg",
},
{
text: "Amazing service! The drivers are professional and the cars are always clean.",
client: "- Chris",
imgSrc: "images/istockphoto-1158014305-612x612.jpg",
},
{
text: "Super reliable and affordable. I use their service for all my city travels.",
client: "- Ashley",
imgSrc: "images/images (3).jpeg",
},
{
text: "Great experience! The cab arrived on time and the driver was very courteous.",
client: "- Michael",
imgSrc: "images/images (4).jpeg",
},
{
text: "Affordable prices and excellent service. Will definitely use again.",
client: "- Sarah",
imgSrc: "images/images (5).jpeg",
},
{
text: "Fast and reliable service. The app makes booking so easy.",
client: "- David",
imgSrc: "images/images (6).jpeg",
},
];
// Shuffle the array to get random testimonials each time
newTestimonials.sort(() => Math.random() - 0.5);
// Clear existing testimonials
testimonialsContainer.innerHTML = "";
// Add the original testimonials back
const originalTestimonials = [
{
text: "Using Cab Rental has made my life so much easier. The service is top-notch and always reliable.",
client: "- Alex",
imgSrc: "images/download3.jpeg",
},
{
text: "The best cab rental service I’ve ever used! The drivers are friendly and always on time.",
client: "- Jordan",
imgSrc: "images/images.jpeg",
},
{
text: "Excellent service! The booking process is seamless, and the cabs are always clean and comfortable.",
client: "- Taylor",
imgSrc: "images/images (4).jpeg",
},
];
originalTestimonials.forEach((testimonial) => {
const testimonialDiv = document.createElement("div");
testimonialDiv.classList.add("testimonial");
const testimonialText = document.createElement("p");
testimonialText.textContent = testimonial.text;
testimonialDiv.appendChild(testimonialText);
const testimonialClient = document.createElement("p");
testimonialClient.classList.add("client");
testimonialClient.textContent = testimonial.client;
testimonialDiv.appendChild(testimonialClient);
const testimonialImg = document.createElement("img");
testimonialImg.src = testimonial.imgSrc;
testimonialImg.alt = testimonial.client.slice(2);
testimonialImg.classList.add("client-photo");
testimonialDiv.appendChild(testimonialImg);
testimonialsContainer.appendChild(testimonialDiv);
});
// Get the button
let mybutton = document.getElementById("topButton");
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
mybutton.addEventListener("click", function() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
});
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
// Add new random testimonials
newTestimonials.slice(0, 3).forEach((testimonial) => {
const testimonialDiv = document.createElement("div");
testimonialDiv.classList.add("testimonial");
const testimonialText = document.createElement("p");
testimonialText.textContent = testimonial.text;
testimonialDiv.appendChild(testimonialText);
const testimonialClient = document.createElement("p");
testimonialClient.classList.add("client");
testimonialClient.textContent = testimonial.client;
testimonialDiv.appendChild(testimonialClient);
const testimonialImg = document.createElement("img");
testimonialImg.src = testimonial.imgSrc;
testimonialImg.alt = testimonial.client.slice(2);
testimonialImg.classList.add("client-photo");
testimonialDiv.appendChild(testimonialImg);
testimonialsContainer.appendChild(testimonialDiv);
});
});