Creating A Sliding Image Navigation Menu With jQuery And CSS3

Creating A Sliding Image Navigation Menu With jQuery And CSS3
File Size: 6.67 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A simple, lightweight jQuery plugin used for creating an image navigation menu that automatically switches between background images with a slice animation when you hover over the menu items.

How to use it:

1. Include the needed jQuery library and Bootstrap's stylesheet on the webpage.

<link rel="stylesheet" href="bootstrap.min.css">
<script src="http://code.jquery.com/jquery-3.1.0.min.js"></script>

2. Include the core JavaScript file slider.js.

<script src="js/slider.js"></script>

3. The required HTML structure for the image navigation menu.

<div class="wrapper">
<ul class="nav-container row">
  <li class="col-sm-4 list-item active bg1">
  </li>
  <li class="col-sm-4 list-item bg1">
  </li>
  <li class="col-sm-4 list-item bg1">
  </li>
  <div class="menu-wrapper">
    <ul>
        <li class="menu-block">
            <div class="link">
                <ul class="menu color-one">
                    <li>Link 1</li>
                    <li>Link 2</li>
                    <li>Link 3</li>
                    <li>Link 4</li>
                </ul>
                <a href="#" class="navigation-header">Category 1</a>
            </div>
        </li>
        <li class="menu-block">
            <div class="link">
                <ul class="menu color-two">
                    <li>Link 1</li>
                    <li>Link 2</li>
                    <li>Link 3</li>
                    <li>Link 4</li>
                </ul>
                <a href="#" class="navigation-header">Category 2</a>
            </div>
        </li>
        <li class="menu-block">
            <div class="link">
                <ul class="menu color-three">
                    <li>Link 1</li>
                    <li>Link 2</li>
                    <li>Link 3</li>
                    <li>Link 4</li>
                </ul>
                <a href="#" class="navigation-header">Category 3</a>
            </div>
        </li>
    </ul>
    <div class="moving-block"></div>
  </div>
</ul>
</div>

4. The primary CSS/CSS3 styles.

.wrapper {
  display: block;
  margin: 0 auto;
  margin-top: 50px;
  height: 542px;
  width: 797px;
  position: relative;
  background-color: #000;
}

.wrapper .nav-container {
  list-style: none;
  display: block;
  float: left;
  width: 100%;
  height: 542px;
  margin: 0;
  padding: 0;
  position: relative;
}

.wrapper .nav-container .list-item {
  background-color: transparent;
  height: 542px;
  border: 1px #000 solid;
  padding: 0;
  position: relative;
}

.wrapper .nav-container .menu-wrapper {
  position: absolute;
  bottom: 85px;
  left: 0;
  width: 100%;
}

.wrapper .nav-container .menu-wrapper > ul {
  display: block;
  float: left;
  width: 100%;
  padding: 0;
  list-style: none;
}

.wrapper .nav-container .menu-wrapper > ul .menu-block {
  width: 265px;
  float: left;
  display: block;
}

.wrapper .nav-container .menu-wrapper > ul .menu-block .link {
  padding: 0;
  width: 100%;
  float: left;
  display: block;
  background-color: transparent;
  text-align: center;
  cursor: pointer;
  position: relative;
}

.wrapper .nav-container .menu-wrapper > ul .menu-block .link a {
  color: #f0f0f0;
  background-color: #000;
  text-decoration: none;
  width: 100%;
  line-height: 40px;
  display: block;
  font-family: tt-r;
  font-weight: bold;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
  -webkit-font-smoothing: antialiased !important;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-stroke: 1px transparent;
}

.wrapper .nav-container .menu-wrapper > ul .menu-block .link .menu {
  list-style: none;
  padding: 0;
  width: 265px;
  display: none;
  position: absolute;
  left: 0;
  z-index: 1600;
  bottom: 40px;
}

.wrapper .nav-container .menu-wrapper > ul .menu-block .link .menu li {
  height: 40px;
  text-align: center;
  color: #f0f0f0;
  line-height: 38px;
  font-family: tt-r;
  font-weight: bold;
  font-size: 15px;
  background-color: transparent;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
  -webkit-font-smoothing: antialiased !important;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-stroke: 1px transparent;
}

.wrapper .nav-container .menu-wrapper > ul .menu-block.active .menu { display: block; }

.moving-block {
  background-color: #80ffce;
  left: 0;
  z-index: 1500;
  display: block;
  position: absolute;
  bottom: 40px;
  width: 265px;
  height: 160px;
  opacity: 0.4;
  display: none;
}

5. Add your own background images to the image navigation menu.

.wrapper .nav-container .bg0 { background-image: url(1.jpg); }

.wrapper .nav-container .bg1 { background-image: url(2.jpg); }

.wrapper .nav-container .bg2 { background-image: url(3.jpg); }

6. Customize the background color for the navigation menu.

.moving-block.color-one { background-color: #80ffce; }

.moving-block.color-two { background-color: #6fa2ff; }

.moving-block.color-three { background-color: #fffb8f; }

7. Initialize the plugin and we're done.

$('.nav-container').slider();

8. Customize the image navigation menu with the following options.

$('.nav-container').slider({

  // starting animation value of picture movements
  startValue: 400, 

  // offset value of picture movements
  offset : 100, 

  // delay value of menu animation
  menuDelay : 400, 

  // colors of sub menus
  menuColor : ['#80ffce','#6fa2ff','#fffb8f']
  
});

This awesome jQuery plugin is developed by sahansira. For more Advanced Usages, please check the demo page or visit the official website.