My current setup includes a basic navbar with an up arrow that slides underneath it when a navigation title is clicked. The arrow initially rests between two nav titles, and when one of them is clicked, some text also slides in.
I am looking to implement a feature where clicking on the same nav title again will slide the arrow back to its original position (defined by the CSS class uparrow
). I am unsure about how to achieve this functionality.
Below is the HTML code snippet:
<div id="bottom">
<div class="middle">
<div class="titles">
<h3>
<a class="webdesign">Web Design</a>
<a class="appdesign">Application Development</a>
</h3>
</div>
<img class="uparrow" src="img/uparrow.png">
<hr>
</div>
<div class="bottom">
<h4>Web Design </h4>
<p>Blah</p>
</div>
<div class="bottom2">
<h4>Application Development</h4>
<p>Blah</p>
</div>
</div>
The following CSS defines the styles for the arrows:
.uparrow {
width:20px;
}
.uparrowleft {
margin-right:180px;
transition: 0.5s ease;
}
.uparrowright {
margin-left:315px;
transition: 0.5s ease;
}
Lastly, here is the jQuery script responsible for handling the arrow sliding animation:
$('.webdesign').click(function() {
$('.bottom2').hide(500);
$('.bottom').toggle(500);
$('.uparrow').removeClass('uparrowright');
$('.uparrow').addClass('uparrowleft');
});
$('.appdesign').click(function() {
$('.bottom').hide(500);
$('.bottom2').toggle(500);
$('.uparrow').removeClass('uparrowleft');
$('.uparrow').addClass('uparrowright');
});