|
| 1 | +<!DOCTYPE html> |
| 2 | + |
| 3 | +<html> |
| 4 | +<head> |
| 5 | + <meta charset="utf-8" /> |
| 6 | + <title>page</title> |
| 7 | + <link rel="stylesheet" type="text/css" href="Image Slider.css"> |
| 8 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 9 | + <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css"> |
| 10 | +</head> |
| 11 | +<body> |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + <div class="picContainer"> |
| 16 | + <h2>JavaScript Image Slider</h2> |
| 17 | + <div id="info"></div> |
| 18 | + <div id="image1" class="img"> |
| 19 | + <img src="https://netresim.com/bilesenler/dosya/dosyalar/image/galeriler/28.01.2017/bresim/Nehir-Ve-Doga-Manzarasi-HD-Wallpapers.jpg" /> |
| 20 | + </div> |
| 21 | + <div id="image2" class="img"> |
| 22 | + <img src="http://3.bp.blogspot.com/-M4taDE-t9c8/U6bQ-7Y-AfI/AAAAAAAACdM/-n9kmDQI7Lk/s1600/doga-hd-wallpaper-hd-resim.jpg" /> |
| 23 | + </div> |
| 24 | + <div id="image3" class="img"> |
| 25 | + <img src="http://1.bp.blogspot.com/-eTaD7Gdgy8c/UrA6fTbCBiI/AAAAAAAACOE/SDiPTpBGH3c/s1600/doga-balon-wallpaper-1980x1200.jpg" /> |
| 26 | + </div> |
| 27 | + <div id="image4" class="img"> |
| 28 | + <img src="https://cdn.wallpapersafari.com/7/90/uK6U2o.jpg" /> |
| 29 | + </div> |
| 30 | + <div class="left" onclick="left()"></div> |
| 31 | + <div class="right" onclick="right()"></div> |
| 32 | + <div class="dots"> |
| 33 | + <div class="dot a1"></div> |
| 34 | + <div class="dot a2"></div> |
| 35 | + <div class="dot a3"></div> |
| 36 | + <div class="dot a4"></div> |
| 37 | + </div> |
| 38 | + </div> |
| 39 | + |
| 40 | + <script> |
| 41 | + |
| 42 | + let i = 0; |
| 43 | + |
| 44 | + let box1 = document.getElementById("image1"); |
| 45 | + let box2 = document.getElementById("image2"); |
| 46 | + let box3 = document.getElementById("image3"); |
| 47 | + let box4 = document.getElementById("image4"); |
| 48 | + let a1 = document.querySelector(".a1"); |
| 49 | + let a2 = document.querySelector(".a2"); |
| 50 | + let a3 = document.querySelector(".a3"); |
| 51 | + let a4 = document.querySelector(".a4"); |
| 52 | + let info = document.getElementById("info"); |
| 53 | + |
| 54 | + a1.onclick = function () { |
| 55 | + box1.style.opacity = 1; |
| 56 | + box2.style.opacity = 0; |
| 57 | + box3.style.opacity = 0; |
| 58 | + box4.style.opacity = 0; |
| 59 | + info.innerHTML = "Image 1" |
| 60 | + i = 0; |
| 61 | + } |
| 62 | + |
| 63 | + a2.onclick = function () { |
| 64 | + box1.style.opacity = 0; |
| 65 | + box2.style.opacity = 1; |
| 66 | + box3.style.opacity = 0; |
| 67 | + box4.style.opacity = 0; |
| 68 | + info.innerHTML = "Image 2" |
| 69 | + i = 1; |
| 70 | + } |
| 71 | + |
| 72 | + a3.onclick = function () { |
| 73 | + box1.style.opacity = 0; |
| 74 | + box2.style.opacity = 0; |
| 75 | + box3.style.opacity = 1; |
| 76 | + box4.style.opacity = 0; |
| 77 | + info.innerHTML = "Image 3" |
| 78 | + i = 2; |
| 79 | + } |
| 80 | + |
| 81 | + a4.onclick = function () { |
| 82 | + box1.style.opacity = 0; |
| 83 | + box2.style.opacity = 0; |
| 84 | + box3.style.opacity = 0; |
| 85 | + box4.style.opacity = 1; |
| 86 | + info.innerHTML = "Image 4" |
| 87 | + i = 3; |
| 88 | + } |
| 89 | + |
| 90 | + document.addEventListener("keydown", (e) => { |
| 91 | + if (e.keyCode == 37) { |
| 92 | + right(); |
| 93 | + } |
| 94 | + }); |
| 95 | + |
| 96 | + document.addEventListener("keydown", (e) => { |
| 97 | + if (e.keyCode == 39 ) { |
| 98 | + right(); |
| 99 | + } |
| 100 | + }); |
| 101 | + |
| 102 | + function right() { |
| 103 | + if (i == 0) { |
| 104 | + box1.style.opacity = 1; |
| 105 | + box2.style.opacity = 0; |
| 106 | + box3.style.opacity = 0; |
| 107 | + box4.style.opacity = 0; |
| 108 | + info.innerHTML = "Image 1" |
| 109 | + i++ |
| 110 | + } |
| 111 | + else if (i == 1) { |
| 112 | + box1.style.opacity = 0; |
| 113 | + box2.style.opacity = 1; |
| 114 | + box3.style.opacity = 0; |
| 115 | + box4.style.opacity = 0; |
| 116 | + info.innerHTML = "Image 2" |
| 117 | + i++ |
| 118 | + } |
| 119 | + else if (i == 2) { |
| 120 | + box1.style.opacity = 0; |
| 121 | + box2.style.opacity = 0; |
| 122 | + box3.style.opacity = 1; |
| 123 | + box4.style.opacity = 0; |
| 124 | + info.innerHTML = "Image 3" |
| 125 | + i++ |
| 126 | + } |
| 127 | + else if (i == 3) { |
| 128 | + box1.style.opacity = 0; |
| 129 | + box2.style.opacity = 0; |
| 130 | + box3.style.opacity = 0; |
| 131 | + box4.style.opacity = 1; |
| 132 | + info.innerHTML = "Image 4" |
| 133 | + i = 0; |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + function left() { |
| 138 | + if (i == 0) { |
| 139 | + box1.style.opacity = 0; |
| 140 | + box2.style.opacity = 0; |
| 141 | + box3.style.opacity = 0; |
| 142 | + box4.style.opacity = 1; |
| 143 | + info.innerHTML = "Image 1" |
| 144 | + i++ |
| 145 | + } |
| 146 | + else if (i == 1) { |
| 147 | + box1.style.opacity = 0; |
| 148 | + box2.style.opacity = 0; |
| 149 | + box3.style.opacity = 1; |
| 150 | + box4.style.opacity = 0; |
| 151 | + info.innerHTML = "Image 2" |
| 152 | + i++ |
| 153 | + } |
| 154 | + else if (i == 2) { |
| 155 | + box1.style.opacity = 0; |
| 156 | + box2.style.opacity = 1; |
| 157 | + box3.style.opacity = 0; |
| 158 | + box4.style.opacity = 0; |
| 159 | + info.innerHTML = "Image 3" |
| 160 | + i++ |
| 161 | + } |
| 162 | + else if (i == 3) { |
| 163 | + box1.style.opacity = 1; |
| 164 | + box2.style.opacity = 0; |
| 165 | + box3.style.opacity = 0; |
| 166 | + box4.style.opacity = 0; |
| 167 | + info.innerHTML = "Image 4" |
| 168 | + i = 0; |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + </script> |
| 173 | + |
| 174 | +</body> |
| 175 | +</html> |
0 commit comments