-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (35 loc) · 1.23 KB
/
Copy pathscript.js
File metadata and controls
51 lines (35 loc) · 1.23 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
function upDate(previewPic){
console.log("Mouse Over");
console.log(previewPic.alt);
console.log(previewPic.src);
let imageDiv = document.getElementById("image");
imageDiv.innerHTML = previewPic.alt;
imageDiv.style.backgroundImage = "url('" + previewPic.src + "')";
}
function unDo(){
let imageDiv = document.getElementById("image");
imageDiv.style.backgroundImage = "url('')";
imageDiv.innerHTML = "Hover over an image below to display here.";
}
// Chạy khi trang web tải xong
function addTabFocus(){
console.log("Page Loaded");
let images = document.querySelectorAll(".gallery img");
for(let i = 0; i < images.length; i++){
console.log("Image " + i);
// Thêm tabindex để có thể dùng phím Tab
images[i].setAttribute("tabindex","0");
// Khi ảnh được chọn bằng bàn phím
images[i].addEventListener("focus", function(){
console.log("Focus");
upDate(this);
});
// Khi rời khỏi ảnh bằng bàn phím
images[i].addEventListener("blur", function(){
console.log("Blur");
unDo();
});
}
}
// Gọi hàm khi trang tải xong
window.onload = addTabFocus;