24
rated 0 times
[
25]
[
1]
/ answers: 1 / hits: 25067
/ 9 Years ago, fri, march 13, 2015, 12:00:00
Here's what I'm trying to make:
- Click on PORTFOLIO;
- Pushes everything down smoothly;
- New links fade-in smoothly;
- Click on PORTFOLIO again, do everything in reverse;
My current code;
$(function () {
$('[data-toggle]').on('click', function () {
var id = $(this).data(toggle),
$object = $(id),
className = open;
if ($object) {
if ($object.hasClass(className)) {
$object.removeClass(className)
} else {
$object.addClass(className)
}
}
});
});
#list {
display: none;
}
#list.open {
display: block;
}
<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<nav>
<ul>
<li><a href=#>Home</a> </li>
<li><a href=#>A Empresa</a> </li>
<li><a href=# class=hide data-toggle=#list>Portfolio</a>
<ul id=list>
<li><a href=#>Comerciais</a> </li>
<li><a href=#>Residenciais</a> </li>
<li><a href=#>Institucionais</a> </li>
<li><a href=#>Edifícios</a> </li>
</ul>
</li>
<li><a href=#>Contato</a> </li>
</ul>
</nav>
It's possible to accomplish this without JS, only with CSS? I have no clue whatsoever how to do the animation part, I tried CSS Transitions propriety, but didn't work.
Also, any tips for the markup and JS? I don't thinks I'm doing it the right way... any tips would be appreciated.
More From » jquery