Adjusting the Underline Navigation Effect with jQuery

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.

JSFIDDLE

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');
});

Answer №1

Does this meet your expectations?

Live demo: https://jsfiddle.net/ek6ktsLg/

The modification involves toggling classes on the elements uparrowleft and uparrowright

$('.webdesign').click(function() {
    $('.bottom2').hide(500);
    $('.bottom').toggle(500);
    $('.uparrow').removeClass('uparrowright');
    $('.uparrow').toggleClass('uparrowleft');
});

$('.appdesign').click(function() {
    $('.bottom').hide(500);
    $('.bottom2').toggle(500);
    $('.uparrow').removeClass('uparrowleft');
    $('.uparrow').toggleClass('uparrowright')
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How do I directly display a variable in index.html using node.js?

Is there a way to retrieve user inputs from the index.html file, process them in Node.js, and then display the result back on the index.html page instead of redirecting to a new page? Form Handling with Express var express = require('express'); ...

The 'Show All' lengthMenu option in Datatables is causing an invalid JSON error

I am experiencing an intermittent 'INVALID JSON' error with my dataTables when selecting 'All' from the lengthMenu select input. Can anyone provide insight into what might be causing this issue? Below is my dataTables script: var ...

How to Filter Fields in AngularJS Based on a Start Date and End Date?

Hey everyone, I'm trying to filter items based on the start and end dates using the daterange functionality in my meanjs app. I've tried multiple approaches but haven't found a solution yet. If anyone knows how to do this, please help me out ...

Displayed hours may not be complete on the Dhtmlx timeline

I'm experiencing an issue with the cell timeline feature in DHTMLX. I want to ensure that the cell size is consistent and displays the full hour, or horizontally scrolls if the hours extend beyond the device screen. Despite my efforts to consult the ...

Scrolling to a specific position on a page when a Vue 3 component appears is a must-do for

When I click a button, my basic form component appears without using the router. I would like the scroll position of the form to automatically move down slightly (for example, on the y-axis at 40) once it is displayed. However, I am unsure of how to achi ...

reversed json using javascript

Is it possible to efficiently reverse the order of the following JSON object: { "10": "..." "11": "...", "12": "...", "13": "...", "14": "...", } so that it becomes: { "14": "...", "13": "...", "12": "...", "11": "... ...

Looking to maintain the value of a toggle button in a specific state depending on certain condition checks

I have a situation where I need to keep a toggle button set to "off" if my collection object is empty. Previously, I was using v-model to update the value of the toggle button. However, now I am attempting to use :value and input events, but I am strugglin ...

Exploring the jSignature feature in jQuery and Laravel models

I'm looking to retrieve the model (Offer) signature using jQuery. When I alert only the model, everything works fine. alert( JSON.stringify(<?php echo $offer; ?>) ); However, when trying to access just the $offer->signature like this alert( ...

Strange Phenomenon: Website Appears Enlarged When Accessed through Server

Similar Question: Why does my website appear smaller on a live server than when deployed locally? After reviewing the answer to the similar question linked above, I still found myself facing the same issue with no resolution. My problem is that the webpa ...

What is the best way to align vertically a horizontal list that includes both headers and icon images?

My goal is to create a horizontal navigation bar that features menu options with headings and icons below them. Upon hovering over each option, the block's background color should change and slightly increase in size. I initially used percentages for ...

To enable the standard PayPal 'donate' button functionality, you can remove the submitHandler from jQuery Validate dynamically

I need to insert a PayPal donate button into the middle of an AngularJS donation form, specifically by nesting the PayPal generated form tags within the donation form tags. This donation form is utilizing an older version (1.12) of jQuery Validate, which ...

Transmit information via AJAX to the @RequestBody annotation in a Spring application

When working with Spring Java, I used response entity and request body to insert data but encountered an error - 404 not found. This is my controller: @RequestMapping(value = "insertuserlogin/", method = RequestMethod.POST) public ResponseEntity<?> ...

"Combining the power of jQuery's empty() method with a parallel

I created a dynamic page using jQuery that fetches new content from the server through AJAX calls. However, I have noticed that there are two main performance bottlenecks - the AJAX call itself and the time-consuming process of removing and unbinding previ ...

At what point does the browser begin fetching the background images specified in a stylesheet?

Are images mentioned in a valid CSS declaration with a background-image value downloaded when the stylesheet is parsed or when the declaration is applied on a page? In simpler terms, do I need to download all background images listed in my stylesheet even ...

What do you notice about interactions involving 'input type=text' in HTML and JavaScript?

When a new binding is created for the value property on an input, any manual modifications by the user no longer update the value. What happens when the binding is altered? Does regular user interaction involve key press listeners? I've modified the ...

Display or conceal <ul>'s using JavaScript when the mouse enters or leaves

I'm encountering an issue with a basic JavaScript function. The goal is to toggle the dropdown menu on my website when the mouse hovers over or leaves the menu. The problem arises because my script is triggered by the ul tags within my menu, and I ha ...

Conceal header and footer bar in Jquery Datatable theme

I need assistance in removing the header/footer bar from this table Here is a visual representation of what I am looking to remove: The jQuery code for this table: $(document).ready(function() { var oTable = $('#tableSmooth').dataTable({ ...

Antonio Mele's latest book on Django3 and Ajax Button Development

After clicking the like button, it shows a count of 2099 instead of 1. However, after refreshing the page, it displays the correct count of 1. The same issue occurs when unliking. The count is accurate only after a refresh, otherwise, it randomly shows eit ...

Flashing background colors on a website

Can anyone explain why this code won't alternate the background color of my website between two different colors? <script type="text/javascript"> function blinkit() { intrvl = 0; for (nTimes = 0; nTimes < 3; nTimes++) { intrv ...

it will still function properly regardless of the width being set to zero

Is anyone able to explain the strange phenomenon I am experiencing with this code snippet? In this particular example, I have set the width of selector h3 to 0. However, when viewing it in IE 9 using F12 development tools, I can see that the width is indee ...