How we can create a stair type hover animation using CSS and JS? Solution: See this Stairway Hover Navigation Using CSS and jQuery, Stairy Type Hover Effect.
Previously I have shared many hover effects and navigation programs, it is a stair type effect on hover. Basically, a navigation hover effect shows an animation effect when we hover on a nav item. It makes the item pretty and different from others to visualize it active or special. And there the stairway type effect takes the active and more items to make a stair type effect.
Today you will learn to create Stair Type Hover Effect for nav items. Basically, there are 4 navigation sections and each section has a little different effect. The first section has 1 step effect, the second sections have 2 step effect, the third has 3 step effect, and the fourth has 4 step effect. Means more steps effect combine upper and lower items and create an effect similar to a stair. And when you will hover up to down or down to up then you will feel stair goes up and down.
So, today I am sharing Stairway Hover Navigation Using CSS and jQuery. There I have used CSS to create the animations and jQuery for dynamic function for change hover position effect. There I have used jQuery to save time and fewer codes, and it is a JS library. You can use this program for navigation or side menu options on the website.
If you are thinking now how this navigation hover effect actually is, then see the preview given below.
Preview Of Stairy Type Hover Effect For Nav
See this video preview to getting an idea of how this nav hover effect looks like.
Now you can see this program visually, also you 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:
Stairway Hover Navigation Using CSS and jQuery Source Code
Before sharing source code, let’s talk about it. First I have created a div and placed a heading tag, and nav tag with 10 nav items inside it. And I have placed the same elements 4 times with different ID names. Because there I created 4 navigations, that’s why I have copied and pasted elements 4 times. Also in the HTML file, I have linked external files like CSS, JS, and jQuery CDN.
Now using CSS I have placed all the items in the right place, as you can see in the preview. With CSS first I gave basic values like size, position, margin, padding, etc to the elements. After that, I gave color values light and dark color combination to visualize the stair better. Also There I have used CSS transform command to scale and change the position of elements.
JavaScript handling here the change active items on hover position change. And also I have declared the stair block values, which mean how many blocks will active on different nav sections. I have used for {} loop command and added and removed class names according to action. Left all other things you will understand after getting the codes, I can’t explain all in writing.
For creating this program you have to create 3 files. First file for HTML, second for CSS, and the third file for JavaScript. Follow the steps to creating this program without any error.
index.html
Create an HTML file named ‘index.html‘ 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 |
<!DOCTYPE html> <!-- Code By Webdevtrick ( https://webdevtrick.com ) --> <html lang="en" > <head> <meta charset="UTF-8"> <title>Stairway Hover Nav | Webdevtrick.com</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="./style.css"> </head> <body> <h1>Stairway Nav</h1> <div> <h2>One Step</h2> <nav id="example-one"> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> </nav> </div> <div> <h2>Two Step</h2> <nav id="example-two"> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> </nav> </div> <div> <h2>Three Steps</h2> <nav id="example-three"> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> </nav> </div> <div> <h2>Four Steps</h2> <nav id="example-four"> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> <a href="#">Nav</a> </nav> </div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/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 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ body { background: #eeeeee; color: #212121; padding: 20px; } body > div { width: 20%; float: left; margin-right: 5%; } h1 { font-size: 36px; margin: 0 0 10px 0; } h2 { margin: 0 0 10px 0; } #example-one { background: #f06d06; } #example-one .active-1 { background: #fa9748; } #example-two { background: #0dacc4; } #example-two .active-1 { background: #40dbf2; } #example-two .active-2 { background: #10ceea; } #example-three { background: #1acd0d; } #example-three .active-1 { background: #41f234; } #example-three .active-2 { background: #2bf11c; } #example-three .active-3 { background: #1de50f; } #example-four { background: #666; } #example-four .active-1 { background: #999999; } #example-four .active-2 { background: #8c8c8c; } #example-four .active-3 { background: gray; } #example-four .active-4 { background: #737373; } nav { -moz-transform: translate3d(0, 0, 0); -ms-transform: translate3d(0, 0, 0); -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); } nav a { display: block; padding: 10px; color: white; text-decoration: none; position: relative; -moz-transition: all 0.2s ease; -o-transition: all 0.2s ease; -webkit-transition: all 0.2s ease; transition: all 0.2s ease; } nav a.active-1 { -moz-transform: scale(1.1) translateX(24px); -ms-transform: scale(1.1) translateX(24px); -webkit-transform: scale(1.1) translateX(24px); transform: scale(1.1) translateX(24px); box-shadow: 0 0 10px rgba(0, 0, 0, 0.75); z-index: 3; } nav a.active-2 { -moz-transform: scale(1.07) translateX(12px); -ms-transform: scale(1.07) translateX(12px); -webkit-transform: scale(1.07) translateX(12px); transform: scale(1.07) translateX(12px); box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); z-index: 2; } nav a.active-3 { -moz-transform: scale(1.04) translateX(4px); -ms-transform: scale(1.04) translateX(4px); -webkit-transform: scale(1.04) translateX(4px); transform: scale(1.04) translateX(4px); z-index: 1; } nav a.active-4 { -moz-transform: scale(1.01) translateX(2px); -ms-transform: scale(1.01) translateX(2px); -webkit-transform: scale(1.01) translateX(2px); transform: scale(1.01) translateX(2px); z-index: 1; } |
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 |
// Code By Webdevtrick ( https://webdevtrick.com ) $.fn.stairwayNav = function(options) { var defaults = { stairs: 3 }; this.options = $.extend({}, defaults, options); var stairs = this.options.stairs; var allLinks = this.find("a"); allLinks .mouseenter(function() { $(this).addClass("active-1"); var index = $(this).index(), i, bef, aft; for(i = 1; i < stairs; i++) { bef = index - i; aft = index + i; allLinks.eq(aft).addClass("active-" + (i+1)); if (bef > 0) { allLinks.eq(bef).addClass("active-" + (i+1)); } } }) .mouseleave(function() { allLinks.removeClass("active-1 active-2 active-3 active-4"); }); return this; }; $("#example-one").stairwayNav({ stairs: 1 }); $("#example-two").stairwayNav({ stairs: 2 }); $("#example-three").stairwayNav({ }); $("#example-four").stairwayNav({ stairs: 4 }); |
That’s It. Now you have successfully created Stairway Hover Navigation Using CSS and jQuery, Stairy Type Hover Effect. If you have any doubt or questions comment down below.
Thanks For Visiting, Keep Visiting.