-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
148 lines (111 loc) · 3.82 KB
/
script.js
File metadata and controls
148 lines (111 loc) · 3.82 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
147
148
//welcome page image
var images = [
'Assets/slides/1.jpg',
'Assets/slides/2.jpg',
'Assets/slides/3.jpg',
'Assets/slides/4.jpg',
'Assets/slides/5.jpg'
];
var currentImageIndex = 0;
var imgButton_r = document.getElementById('wr-arrow');
var imgButton_l = document.getElementById('wl-arrow');
var image_Element = document.getElementById('main');
function changeImage() {
console.log(currentImageIndex)
currentImageIndex++;
if (currentImageIndex >= images.length) {
currentImageIndex = 0;
}
console.log(image_Element);
image_Element.style.backgroundImage = `url(${images[currentImageIndex]})`;
}
function changeImageReverse() {
console.log(currentImageIndex)
currentImageIndex--;
if (currentImageIndex === -1) currentImageIndex = images.length - 1;
image_Element.style.backgroundImage = `url(${images[currentImageIndex]})`;
}
// Call the changeImage function every 5 seconds
setInterval(changeImage, 2000);
console.log(234);
imgButton_r.addEventListener('click', function () {
changeImage();
event.preventDefault();
});
imgButton_l.addEventListener('click', function () {
changeImageReverse();
event.preventDefault();
});
// products arrow key
var scrollButton_r = document.getElementById('scroll-button-r');
var scrollButton_l = document.getElementById('scroll-button-l');
var scrollContainer = document.getElementById('products-scroll');
scrollButton_r.addEventListener('click', function () {
// Scroll the scroll bar 200px
scrollContainer.scrollBy({
left: 200,
behavior: 'smooth' // Enable smooth scrolling
});
});
scrollButton_l.addEventListener('click', function () {
// Scroll the scroll bar 200px tp right side
scrollContainer.scrollBy({
left: -200,
behavior: 'smooth' // Enable smooth scrolling
});
});
var categories = [
{ id: "Toyota", text: "Toyota" },
{ id: "Honda", text: "Honda" },
{ id: "Mitsubishi", text: "Mitsubishi" },
{ id: "BMW", text: "BMW" },
{ id: "Hyundai", text: "Hyundai" },
{ id: "main", text: "Home" },
{ id: "brands", text: "Brands" },
{ id: "about", text: "About us" },
{ id: "products", text: "Products" },
{ id: "contact", text: "Contact" },
];
var links = ["main", "brands", "about", "products", "contact"]
//search suggestions
var input = document.getElementById('searchBox');
var dropdown = document.getElementById('dropdown');
var search_btn = document.getElementById('search-btn');
input.addEventListener('input', function () {
var enteredText = input.value.toLowerCase();
var matchedItems = categories.filter(function (item) {
return item.text.toLowerCase().includes(enteredText.toLowerCase());
});
// Generate the dropdown content
var dropdownContent = '';
for (var i = 0; i < matchedItems.length; i++) {
dropdownContent += '<div>' + matchedItems[i].text + '</div>';
}
// Display or hide the dropdown
if (matchedItems.length > 0) {
dropdown.innerHTML = dropdownContent;
dropdown.style.display = 'block';
} else {
dropdown.style.display = 'none';
}
});
// Close the dropdown when clicking outside
document.addEventListener('click', function (event) {
if (!dropdown.contains(event.target) && !input.contains(event.target)) {
dropdown.style.display = 'none';
}
});
// Handle dropdown item selection
dropdown.addEventListener('click', function (event) {
var selectedText = event.target.textContent;
input.value = selectedText;
dropdown.style.display = 'none';
});
// search button function
search_btn.addEventListener("click", ()=>{
var enteredText = input.value.toLowerCase();
if(links.includes(enteredText)){
const element = document.getElementById(enteredText);
element.scrollIntoView({ behavior: 'smooth' });
}
})