1

Create an Image Menu with jQuery

The web developers at Maui Website Design have designed a dynamic image menu that allows you to navigate easily through any visual content with a Motools-inspired effect, powered by jQuery Javascript.

The menu’s main functions require a jQuery-compatible script, a valid XHTML, a Motools-like sliding effect, and it should be lightweight. It comes in two versions, the first of which you can view HERE.

Image Menu Create an Image Menu with jQuery Click on the image to download the source.

 

Step 1: HTML

<div class="jimgMenu">
<ul>
<li><a href="#">Landscapes</a></li>
<li><a href="#">People</a></li>
<li><a href="#">Nature</a></li>
<li><a href="#">Abstract</a></li>
<li><a href="#">Urban</a></li>
</ul>
</div>

Step 2: CSS

.jimgMenu {
position: relative;
width: 670px;
height: 200px;
overflow: hidden;
margin: 25px 0px 0px;
}
.jimgMenu ul {
list-style: none;
margin: 0px;
display: block;
height: 200px;
width: 1340px;
}
.jimgMenu ul li {
float: left;
}
.jimgMenu ul li a {
text-indent: -1000px;
background:#FFFFFF none repeat scroll 0%;
border-right: 2px solid #fff;
cursor:pointer;
display:block;
overflow:hidden;
width:78px;
height: 200px;
}
.jimgMenu ul li.landscapes a {
background: url(images/landscapes.jpg) repeat scroll 0%;
}
.jimgMenu ul li.people a {
background: url(images/people.jpg) repeat scroll 0%;
}
.jimgMenu ul li.nature a {
background: url(images/nature.jpg) repeat scroll 0%;
}
.jimgMenu ul li.abstract a {
background: url(images/abstract.jpg) repeat scroll 0%;
}
.jimgMenu ul li.urban a {
background: url(images/urban.jpg) repeat scroll 0%;
min-width:310px;
}

Step 3: Javascript

Include jQuery and all plugin files listed in the header of your HTML file. It should look like this:

<link href="css/jimgMenu.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-easing-1.3.pack.js"></script>
<script type="text/javascript" src="js/jquery-easing-compatibility.1.2.pack.js"></script>

Include the jQuery in your attached file or page.

<script type="text/javascript">
$(document).ready(function () {
// find the elements to be eased and hook the hover event
$('div.jimgMenu ul li a').hover(function() {
// if the element is currently being animated
if ($(this).is(':animated')) {
$(this).stop().animate({width: "310px"}, {duration: 450, easing:"easeOutQuad", complete: "callback"});
} else {
// ease in quickly
$(this).stop().animate({width: "310px"}, {duration: 400, easing:"easeOutQuad", complete: "callback"});
}
}, function () {
// on hovering out, ease the element out
if ($(this).is(':animated')) {
$(this).stop().animate({width: "78px"}, {duration: 400, easing:"easeInOutQuad", complete: "callback"})
} else {
// ease out slowly
$(this).stop(':animated').animate({width: "78px"}, {duration: 450, easing:"easeInOutQuad", complete: "callback"});
}
});
});
</script>

In the second version, kwicks are used to add functionality and help to the Sliding Image Menu animation. Get the DEMO and SOURCE here.

 

Step 1: HTML

<div class="jimgMenu">
<ul>
<li id="landscapes"><a href="#">Landscapes</a></li>
<li id="people"><a href="#">People</a></li>
<li id="nature"><a href="#">Nature</a></li>
<li id="abstract"><a href="#">Abstract</a></li>
<li id="urban"><a href="#">Urban</a></li>
</ul>
</div>

Step 2: CSS

(Adapted for kwicks)
.jimgMenu {
position:relative;
margin: 0px 0px 0px 50px;
padding: 0px;
width:475px;
height:200px;
overflow: hidden;
}
.jimgMenu ul {
list-style: none;
margin: 0px;
padding: 0px;
display: block;
height: 200px;
position: relative;
}
.jimgMenu ul li {
width: 95px;
float: left;
display: block;
overflow: hidden;
}
.jimgMenu ul li a {
text-indent: -1000px;
background:#fff repeat scroll 0%;
border-right: 2px solid #fff;
cursor:pointer;
display:block;
overflow: hidden;
height: 200px;
}
.jimgMenu ul li#landscapes a {
background: url(images/landscapes.jpg) repeat scroll 0%;
}
.jimgMenu ul li#people a {
background: url(images/people.jpg) repeat scroll 0%;
}
.jimgMenu ul li#nature a {
background: url(images/nature.jpg) repeat scroll 0%;
}
.jimgMenu ul li#abstract a {
background: url(images/abstract.jpg) repeat scroll 0%;
}
.jimgMenu ul li#urban a {
background: url(images/urban.jpg) repeat scroll 0%;
border-right-style: none;
}

Step 3: Javascript

Include the jQuery and all files below in the header section of your HTML.

<link href="css/jimgMenukwicks.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-easing-1.3.pack.js"></script>
<script type="text/javascript" src="js/jquery-easing-compatibility.1.2.pack.js"></script>
<script type="text/javascript" src="js/jquery.kwicks-1.5.1.pack.js"></script>
The above code will activate jQuery Sliding Image Menu plugin. Lastly, place the script below in your html head or document body.
<script type="text/javascript">
$().ready(function() {
$('.jimgMenu ul').kwicks({max: 310, duration: 300, easing: 'easeOutQuad', complete: 'callback'});
});
</script>

 

Take note that CSS controls most of the image menu’s style and if you want to customize the easing type and duration, use the jQuery easing plugin to achieve different sliding effects.

 


Incoming search terms for the article:

Related Posts

Create Google Play’s Tab Navigation Using jQuery And CSS

PS Advanced Compositioning

How To Create A Triangular Pixelation Effect Using Photoshop

How to Create Subtle Caption Hover Effects

1 Comment

  1. Lilou

    04.11.2012

    hi, I’ve tried it but without success, I really want it for my blog, can you help me?