Reputation: 231
I am trying to make this navigation for a website, and it seems to work now, i just cant get the right animation. I have tried to use animate, but i could not make it work and im not sure if thats even the best way to go arround it.
I want my menus to slide in from the side they live in - not scale down from the top corner as the standard .show / .hide does.
HTML
<div class="wrapper">
<div class="nav">
<a href="#" class="nav-show">menu</a>
<a href="#" class="search-show">search</a>
<div class="nav-wrap">
<ul>
<li><a herf="#">1</a></li>
<li><a herf="#">2</a></li>
<li><a herf="#">3</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
</ul>
</div>
<div class="search-wrap">
<ul>
<li><a herf="#">1</a></li>
<li><a herf="#">2</a></li>
<li><a herf="#">3</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
</ul>
</div>
</div>
</div>
CSS
body {background-color:#567;}
* {margin:0; padding:0;}
ul, li {margin:0; padding:0;}
.wrapper {width:100%; height:60px; background-color:#333;}
.nav {width:100%; height:60px;}
.nav-show {width:60px; background-color:#666; color:#FFF; display:inline-block; height:100%; line-height:60px; text-align:center;}
.search-show {width:60px; background-color:#666; color:#FFF; display:inline-block; height:100%; line-height:60px; text-align:center; float:right;}
.nav-wrap {width:90%; background-color:#999; color:#000;padding:10px; display:none; position:fixed; top:60px; left:0; bottom:0; overflow:auto;}
.nav-wrap ul {list-style:none; background-color:#F60;}
.nav-wrap ul li {height:60px; width:100%; background-color:#CCC;margin-bottom:5px;}
.search-wrap {width:90%; background-color:#999; color:#000;padding:10px; display:none; position:fixed; top:60px; right:0; bottom:0; overflow:auto;}
.search-wrap ul {list-style:none; background-color:#F60;}
.search-wrap ul li {height:60px; width:100%; background-color:#CCC;margin-bottom:5px;}
JQUERY
$(document).ready(
function(){
$(".nav-show").click(function () {
$(".search-wrap").hide("slow");
$(".nav-wrap").toggle("slow");
});
$(".search-show").click(function () {
$(".nav-wrap").hide("slow");
$(".search-wrap").toggle("slow");
});
});
i also made a fiddle
i know my jquery code is not the best, im rather rookie here, so if it can be done smarter, i would love to see it. Maybe it would be better to just use CSS3 for animation?
Upvotes: 1
Views: 172
Reputation: 1279
Fixed it per your needs
new jsFiddle
HTML:
<div class="nav-wrap hidden">
<ul>
<li><a herf="#">1</a></li>
<li><a herf="#">2</a></li>
<li><a herf="#">3</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
</ul>
</div>
<div class="search-wrap hidden">
<ul>
<li><a herf="#">1</a></li>
<li><a herf="#">2</a></li>
<li><a herf="#">3</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
<li><a herf="#">4</a></li>
</ul>
</div>
JS:
$(document).ready(
function(){
$(".nav-show").click(function () {
$(".search-wrap").hide('slide', {direction: 'right'}, 1000);
$(".search-wrap").addClass("hidden");
if($(".nav-wrap").hasClass('hidden')){
$(".nav-wrap").show('slide', {direction: 'left'}, 1000);
$(".nav-wrap").removeClass("hidden");
} else {
$(".nav-wrap").addClass("hidden");
$(".nav-wrap").hide('slide', {direction: 'left'}, 1000)
}
});
$(".search-show").click(function () {
$(".nav-wrap").hide('slide', {direction: 'left'}, 1000);
$(".nav-wrap").addClass("hidden");
$(".search-wrap").show('slide', {direction: 'right'}, 1000);
if($(".search-wrap").hasClass('hidden')){
$(".search-wrap").show('slide', {direction: 'right'}, 1000);
$(".search-wrap").removeClass("hidden");
} else {
$(".search-wrap").addClass("hidden");
$(".search-wrap").hide('slide', {direction: 'right'}, 1000)
}
});
});
Upvotes: 1
Reputation: 1927
Try with easing plugin, looks great:
$(document).ready(
function(){
$(".nav-show").click(function () {
$(".search-wrap").hide("slow");
$(".nav-wrap").toggle('slide', {direction: 'left'}, 1000, "easeOutExpo");
});
$(".search-show").click(function () {
$(".nav-wrap").hide("slow");
$(".search-wrap").toggle('slide', {direction: 'right'}, 1000, "easeOutExpo");
});
});
Upvotes: 0