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

Adjust the dimensions of the image carousel in Twitter Bootstrap

Here is the code that I am currently working with: <div class="col-sm-4"> <div class="card"> <div class="card-block"> <div class="col-sm-4"> <div id="carouselExampleIndi ...

Using jQuery to retrieve the initial object in an array following an Ajax request

I need to retrieve the first object returned by an AJAX call before looping through it with the each() function. Here's the current code that successfully loops through the data: $.each(obj.DATA, function(indexInArray, value) { var depts ...

Ways to troubleshoot and resolve the jQuery error with the message "TypeError: 'click' called"

I am currently developing a project for managing Minecraft servers, focusing on a configuration panel. I have set up a form that users need to fill out in order to configure the settings and send the values using Ajax. However, I encountered an error: Type ...

Save the Ajax "stack" variable to a text file rather than duplicating it

I have a question regarding posting variables to a .txt file. The variable in question is '10'. However, every time I post the variable, the .txt file simply keeps adding "10" instead of stacking it. Ideally, I want it to display 10 on the first ...

Having trouble with jQuery after adding more content?

I recently started delving into the world of javascript, incorporating it into my website. Just last week, I came across a script that utilizes jQuery to load extra content onto my page. Initially, everything seemed to be functioning smoothly until I reali ...

When checking if el.text() is equal to "string", it will return false, regardless of the actual content of the element being "string"

Looking at the code snippet below, it seems that the else block is always being executed instead of the if block. The alert confirms that the variable state has the value 'payment' as expected. var state = $('.check-state').text(); ale ...

Incorporate a class into a link within the wp_list_pages function

I've been experimenting with creating a hover effect on list items using the wp_list_pages() function in my Wordpress theme. Despite my efforts, I've hit a roadblock in getting the hover effect to work properly. As a beginner in web development, ...

Unveiling hidden elements through jQuery

Could someone provide me with insight as to why the reveal button on this page is not functioning properly and revealing all content? If you have a different solution for hiding/revealing most elements except a few, I would greatly appreciate your suggest ...

Add a Variety of Data Entries to a Table

I am currently attempting to add multiple pieces of data (from a date form) into a table using Jquery and MomentJS. However, the output does not appear as desired. Below is my code: $(".btnNext").on('click', function(e) { var Day = 1; ...

Leveraging jQuery to delay the processing of AJAX requests

Managing a list of 15+ ajax requests that need to be executed in a specific sequence can be challenging. Each ajax call must wait for the previous one to finish before proceeding. This issue is compounded by the fact that the callback function for each aja ...

Bottom-fixed navigation bar with adhesive functionality

I have been attempting to create a navigation bar that starts at the bottom of the page and then sticks to the top as the user scrolls, similar to the functionality on this website (http://grovemade.com). However, I have had little success so far. Could s ...

position text to the right side of a slider gallery created with JavaScript

I'm currently utilizing a WordPress plugin known as Slideshow Gallery and I want to position the text below it to float next to the gallery on the right side. I've attempted the following: .bioText{ font-size: 14px; font-size: 1.428571429rem; ...

Trigger the meteor template to render manually upon any changes in the database

Currently, I am using a meteorjs template to display some records. What I am trying to achieve is that whenever there is a change in the database, I would like to trigger the template render method manually. Is it possible to reload just a single template ...

The WebRTC video feature is functioning on the local network but is encountering difficulties

Trying to grasp WebRTC has been quite the journey for me. In an attempt to troubleshoot my failed video transfer between computers, I uploaded what I have so far onto a temporary github repository: https://github.com/stevendesu/webrtc-failure My goal is ...

The functionality of dropdown menus in the Bootstrap 5 navbar is currently experiencing issues

I recently updated my Bootstrap from v5.2.2 to v5.2.3 and now the dropdown menus in my navbar are not working properly. They do not drop down as they should, instead, they remain stationary. Can someone please help me figure out what I am doing wrong? & ...

Is using float:right making the jquery slide toggle dropdown div (triggered by hover) appear glitchy?

Utilizing jQuery's slidetoggle and hover functions, I have successfully implemented a dropdown feature in my div. Within this div, there is various information displayed including the date, a note counter, and three buttons. The first two are Tumblr ...

Struggling to create a SVG Line with DOM Manipulation in Typescript

I'm having trouble adding an SVG element to my div using the appendChild function in TypeScript. I want to add a line inside the SVG, but for some reason, I can't see the line output on my browser. There are no errors showing up either. Please he ...

Tips for creating responsive text within a hero image

I'm exploring the world of creating responsive websites using Bootstrap, a new venture for me. One challenge I've encountered is trying to create a hero image with text positioned perfectly in the center. Despite my efforts, the text does not adj ...

Tips for making a fluid DIV expand to fit the entire width of the page

My layout features fixed-width sidebars on the left and right, with a fluid main content area that fills the space in between using float:left. Here's an example: #left-sidebar {width: 200px;} #right-sidebar {width: 300px;} #main-content {margin-left ...

creating an interactive table with the help of the useState hook

I'm new to JavaScipt and ReactJS, so I have a question that may seem obvious but I can't seem to figure it out. I am attempting to display my array in a table using useState, but currently I can only show the header. Additionally, if anyone know ...