How we can create a modern type hover slider using HTML CSS JavaScript? Solution: See this jQuery Modern Hover Slider With CSS, Image Change On Hover.
Previously I have shared many types of slider, but this is something different from those. Basically, there are some text and their own image, when you hover on a text then you can see the image of it in the background. This is an also kind of image change program on hover.
Today you will learn to create image change on hover program. There are 5 navigation items when you will hover on it, then its featured image will appear on the background also on the left side you will see the item’s name in large font. Also the cursor has an amazing effect, its show negative sides of elements on hover.
So, Today I am sharing jQuery Modern Hover Slider With CSS. There I have used jQuery, as you know it is a JS library that’s why I am putting this in JavaScript section. Also used Bootstrap to just creating the layout. I think this program will be useful, interesting and something new for you, after learning that you can use it on your website.
If you are thinking now how this image change program actually is, then see the preview given below.
Preview of Image Change on Hover Program
See this video preview to getting an idea of how this program looks like.
Now you can see this visually, you also can see it live by pressing the button given above. If you like this, then get the source code of its.
You May Also Like:
jQuery Modern Hover Slider With CSS Source Code
Before sharing source code, let’s talk about it. As you can see in the preview there is image, text and side text in the program. First, using HTML I have created all these elements using div and list. I have placed left side text and image inside the main div and put list above the image as you can see.
There I have also created 3 more divs for creating the cursor effect which is handled by jquery. Now using CSS I have placed all the elements on the right place, there I have done many works using CSS. This design is also responsive means it will fit on every screen size, for creating the responsive design I have used CSS @media query (info).
Now in JavaScript file which is powered by jQuery, I have put some conditions. Using JS first I have done the cursor’s function as given in the preview. After that, I have put some conditions like when hovering on any heading then its image will visible and other’s will hide. Left other things you will understand after getting the codes, I can’t explain in writing.
For creating this program you have to create 3 files. First for HTML, second for CSS, and the third for JavaScript. Follow the steps to creating this without any error.
index.html
Create an HTML file named ‘index.html‘ and put these codes given below.
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 |
<!DOCTYPE html> <!--Code By Webdevtrick ( https://webdevtrick.com )--> <html lang="en" > <head> <meta charset="UTF-8"> <title>jQuery Hover Slider | Webdevtrick.com</title> <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css'> <link rel="stylesheet" href="style.css"> </head> <body> <div class="center"> <div class="left-text">gadget</div> <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="img-wrap"> <img src="https://webdevtrick.com/wp-content/uploads/gadget.jpg" alt=""> </div> </div> </div> </div> </div> <div class="center"> <div class="left-text">hardware</div> <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="img-wrap"> <img src="https://webdevtrick.com/wp-content/uploads/hardware.jpg" alt=""> </div> </div> </div> </div> </div> <div class="center"> <div class="left-text">coding</div> <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="img-wrap"> <img src="https://webdevtrick.com/wp-content/uploads/programming.jpg" alt=""> </div> </div> </div> </div> </div> <div class="center"> <div class="left-text">design</div> <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="img-wrap"> <img src="https://webdevtrick.com/wp-content/uploads/design.jpg" alt=""> </div> </div> </div> </div> </div> <div class="center"> <div class="left-text">automob</div> <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="img-wrap"> <img src="https://webdevtrick.com/wp-content/uploads/auto.jpg" alt=""> </div> </div> </div> </div> </div> <div class="section padding-top-bottom over-hide bigger"> <ul class="slide-buttons"> <li class=""> <a href="#" class="hover-target" data-hover="gadget">gadget</a> </li> <li class=""> <a href="#" class="hover-target" data-hover="hardware">hardware</a> </li> <li class=""> <a href="#" class="hover-target" data-hover="coding">coding</a> </li> <li class=""> <a href="#" class="hover-target" data-hover="design">design</a> </li> <li class=""> <a href="#" class="hover-target" data-hover="auto-m">auto-m</a> </li> </ul> </div> <div class='cursor' id="cursor"></div> <div class='cursor2' id="cursor2"></div> <div class='cursor3' id="cursor3"></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script> <script src="function.js"></script> </body> </html> |
style.css
Now create a CSS file named ‘style.css‘ and put these codes given here.
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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ @import url('https://fonts.googleapis.com/css?family=Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&subset=devanagari,latin-ext'); body{ width: 100%; height: 100vh; background: #1f2029; overflow-x: hidden; font-family: 'Poppins', sans-serif; font-size: 16px; line-height: 30px; -webkit-transition: all 300ms linear; transition: all 300ms linear; } p { font-family: 'Poppins', sans-serif; font-size: 16px; line-height: 30px; color: #fff; -webkit-transition: all 300ms linear; transition: all 300ms linear; } ::selection { color: #fff; background-color: #000; } ::-moz-selection { color: #fff; background-color: #000; } mark{ color: #fff; background-color: #000; } .section { position: relative; width: 100%; display: block; z-index: 30 !important; } .over-hide { overflow: hidden; } .padding-top-bottom { padding-top: 90px; padding-bottom: 90px; } .center{ position: fixed; top: 50%; left: 0; width: 100%; z-index: 10; transform: translateY(-50%); opacity: 0; -webkit-transition: all 300ms linear; transition: all 300ms linear; } .center.show{ opacity: 1; } .center .left-text{ position: absolute; top: -50%; left: -20px; height: 200%; z-index: 1; font-family: 'Poppins', sans-serif; font-weight: 900; text-align: center; -webkit-writing-mode: vertical-lr; writing-mode: vertical-lr; font-size: 7vw; line-height: 1; color: rgba(200,200,200,.1); background: linear-gradient(90deg, rgba(200,200,200,0), rgba(200,200,200,0.1)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; line-height: 1; -webkit-transition: all 300ms linear; transition: all 300ms linear; } .center.show .left-text{ left: 0; } .bigger { z-index: 30 !important; } .img-wrap { position: relative; width: 100%; overflow: hidden; border-radius: 4px; box-shadow: 0 3px 5px rgba(0, 0, 0, 0.02); display: block; transform: scale(1.03); -webkit-transition: all 300ms linear; transition: all 300ms linear; } .center.show .img-wrap{ transform: scale(1); } .img-wrap img { width: 100%; height: auto; display: block; } .cursor, .cursor2, .cursor3{ position: fixed; border-radius: 50%; transform: translateX(-50%) translateY(-50%); pointer-events: none; left: -100px; top: 50%; mix-blend-mode: difference; -webkit-transition: all 300ms linear; transition: all 300ms linear; z-index: 9999999; } .cursor{ background-color: #fff; height: 0; width: 0; z-index: 9999999; } .cursor2,.cursor3{ height: 36px; width: 36px; z-index:99998; -webkit-transition:all 0.3s ease-out; transition:all 0.3s ease-out } .cursor2.hover, .cursor3.hover{ -webkit-transform:scale(2) translateX(-25%) translateY(-25%); transform:scale(2) translateX(-25%) translateY(-25%); border:none } .cursor2{ border: 2px solid #fff; box-shadow: 0 0 12px rgba(255, 255, 255, 0.2); } .cursor2.hover{ background: rgba(255,255,255,1); box-shadow: 0 0 0 rgba(255, 255, 255, 0.2); } .link-to-page { position: fixed; top: 30px; right: 30px; z-index: 20000; cursor: pointer; width: 30px; } .link-to-page img{ width: 100%; height: auto; display: block; } .slide-buttons{ position: relative; padding: 0; margin: 0 auto; text-align: center; width: 580px; max-width: 100%; padding-left: 20px; padding-right: 20px; list-style: none; } .slide-buttons li{ position: relative; padding: 0; margin: 0 auto; text-align: center; margin: 60px 0; display: block; list-style: none; -webkit-transition: all 300ms linear; transition: all 300ms linear; } .slide-buttons li a{ position: relative; display: inline-block; font-family: 'Poppins', sans-serif; font-weight: 900; font-size: 100px; line-height: 1; text-transform: uppercase; -webkit-text-stroke: 2px #fff; text-stroke: 2px #fff; -webkit-text-fill-color: transparent; text-fill-color: transparent; color: transparent; opacity: 0.3; -webkit-transition: all 300ms linear; transition: all 300ms linear; } .slide-buttons li.active a{ opacity: 1; } .slide-buttons li a:hover{ text-decoration: none; } .slide-buttons li a:focus, .slide-buttons li a:active{ border: none; outline: none; box-shadow: none; } .slide-buttons li a::before { position: absolute; top: 0; left: 0; font-family: 'Poppins', sans-serif; font-weight: 900; font-size: 100px; line-height: 1; overflow: hidden; text-transform: uppercase; padding: 0; max-height: 0; -webkit-text-stroke: transparent; text-stroke: transparent; -webkit-text-fill-color: #fff; text-fill-color: #fff; color: #fff; content: attr(data-hover); -webkit-transition: max-height 0.4s; -moz-transition: max-height 0.4s; transition: max-height 0.4s; } .slide-buttons li.active a::before, .slide-buttons li a:active::before, .slide-buttons li a:focus::before { max-height: 100%; } body.light{ background: #fff; } body.light p{ color: #1f2029; } body.light h3{ color: var(--dark); } body.light .cursor, body.light .cursor2, body.light .cursor3{ mix-blend-mode: difference; z-index: 9999999 !important; } body.light .cursor.hover, body.light .cursor2.hover, body.light .cursor3.hover{ } body.light .cursor{ background-color: #1f2029; } body.light .cursor2{ height: 16px; width: 16px; background-color: #1f2029; box-shadow: 0 0 12px rgba(0, 0, 0, 0.2); mix-blend-mode: difference; border-color: transparent; } body.light .cursor.hover, body.light .cursor2.hover, body.light .cursor3.hover{ opacity: 0; } body.light .cursor2.hover{ background: rgba(0,0,0,1); box-shadow: 0 0 0 rgba(0, 0, 0, 0.2); } body.light .slide-buttons li a{ -webkit-text-stroke: 2px #1f2029; text-stroke: 2px #1f2029; -webkit-text-fill-color: transparent; text-fill-color: transparent; color: transparent; opacity: 1; } body.light .slide-buttons li a::before { -webkit-text-stroke: transparent; text-stroke: transparent; -webkit-text-fill-color: #1f2029; text-fill-color: #1f2029; color: #1f2029; } body.light .center.show{ margit-top: 0; opacity: 0.9; } body.light .center .left-text{ color: rgba(0,0,0,.16); background: linear-gradient(90deg, rgba(0,0,0,0), rgba(0,0,0,0.16)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; } @media (max-width: 1199px) { .center .left-text{ font-size: 13vw; } .slide-buttons li{ margin: 50px 0; } .slide-buttons li a{ font-size: 80px; } .slide-buttons li a::before { font-size: 80px; } } @media (max-width: 991px) { .center .left-text{ font-size: 16vw; } } @media (max-width: 767px) { .cursor, .cursor2, .cursor3{ display: none; } .center .left-text{ display: none; } .slide-buttons li{ margin: 40px 0; } .slide-buttons li a{ font-size: 60px; font-weight: 700; } .slide-buttons li a::before { font-size: 60px; font-weight: 700; } } @media (max-width: 575px) { .slide-buttons li a{ font-size: 50px; font-weight: 700; } .slide-buttons li a::before { font-size: 50px; font-weight: 700; } } |
function.js
The final step, Create a JavaScript file named ‘function.js‘ and put the codes.
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 |
// Code By Webdevtrick ( https://webdevtrick.com ) (function($) { "use strict"; document.getElementsByTagName("body")[0].addEventListener("mousemove", function(n) { t.style.left = n.clientX + "px", t.style.top = n.clientY + "px", e.style.left = n.clientX + "px", e.style.top = n.clientY + "px", i.style.left = n.clientX + "px", i.style.top = n.clientY + "px" }); var t = document.getElementById("cursor"), e = document.getElementById("cursor2"), i = document.getElementById("cursor3"); function n(t) { e.classList.add("hover"), i.classList.add("hover") } function s(t) { e.classList.remove("hover"), i.classList.remove("hover") } s(); for (var r = document.querySelectorAll(".hover-target"), a = r.length - 1; a >= 0; a--) { o(r[a]) } function o(t) { t.addEventListener("mouseover", n), t.addEventListener("mouseout", s) } $(document).ready(function() { $('.slide-buttons li:nth-child(1)').on('mouseenter', function() { $('.slide-buttons li.active').removeClass('active'); $('.center.show').removeClass("show"); $('.center:nth-child(1)').addClass("show"); $('.slide-buttons li:nth-child(1)').addClass('active'); }) $('.slide-buttons li:nth-child(2)').on('mouseenter', function() { $('.slide-buttons li.active').removeClass('active'); $('.center.show').removeClass("show"); $('.center:nth-child(2)').addClass("show"); $('.slide-buttons li:nth-child(2)').addClass('active'); }) $('.slide-buttons li:nth-child(3)').on('mouseenter', function() { $('.slide-buttons li.active').removeClass('active'); $('.center.show').removeClass("show"); $('.center:nth-child(3)').addClass("show"); $('.slide-buttons li:nth-child(3)').addClass('active'); }) $('.slide-buttons li:nth-child(4)').on('mouseenter', function() { $('.slide-buttons li.active').removeClass('active'); $('.center.show').removeClass("show"); $('.center:nth-child(4)').addClass("show"); $('.slide-buttons li:nth-child(4)').addClass('active'); }) $('.slide-buttons li:nth-child(5)').on('mouseenter', function() { $('.slide-buttons li.active').removeClass('active'); $('.center.show').removeClass("show"); $('.center:nth-child(5)').addClass("show"); $('.slide-buttons li:nth-child(5)').addClass('active'); }) $('.slide-buttons li:nth-child(6)').on('mouseenter', function() { $('.slide-buttons li.active').removeClass('active'); $('.center.show').removeClass("show"); $('.center:nth-child(6)').addClass("show"); $('.slide-buttons li:nth-child(6)').addClass('active'); }) $('.slide-buttons li:nth-child(1)').trigger('mouseenter') }); })(jQuery); |
That’s It. Now you have successfully created jQuery Modern Hover Slider With CSS, Image Change On Hover Program. If you have any doubt or question comment down below.