Pointer beneath navigation option

I have created a menu that includes an arrow underneath which slides under the selected item. This arrow is identified by the class "marker".

Here is the HTML code:

<div class="services-block">
  <div id="services-carousel" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner services" role="listbox" >
      <div class="item active" id="services">
        <ul class="tabbed-menu menu-list">
          <li><a href="javascript:rudrSwitchTab('tb_1', 'content_1');" id="tb_1" class="tabmenu active">IT Consulting</a></li>
          <li><a href="javascript:rudrSwitchTab('tb_2', 'content_2');" id="tb_2" class="tabmenu">Customer Relationship Management</a></li>
          <li><a href="javascript:rudrSwitchTab('tb_3', 'content_3');" id="tb_3" class="tabmenu">Business Intelligence</a></li>
          <li><a href="javascript:rudrSwitchTab('tb_4', 'content_4');" id="tb_4" class="tabmenu">Tourism and Hospitality</a></li>
          <li><a href="javascript:rudrSwitchTab('tb_5', 'content_5');" id="tb_5" class="tabmenu">Finance and Banking</a></li>
          <li><a class="right carousel-control" href="#services-carousel" role="button" data-slide="next">More <img src="images/right-arrow.png" alt=""></a></li>
       </ul>                 
     </div> <!--/.item active-->

   </div> <!--/.carousel-inner-->
   <div id="marker"></div>
 </div> <!--/#services-carousel-->
</div> <!--services-block-->

Using jQuery, here is how I handle the marker movement:

$("#services ul > li").click(function(event){
    var position = $(this).position();
    var width    = Math.round($(this).width()/2) - 5;
    $("#marker").css('left', 'auto').transition({ x: position.left + width });
    event.preventDefault();
})

Initially, the marker is positioned 14% to the left upon page load. However, I remove this styling in jQuery to prevent the marker from sliding to the left when clicking on another item. Is there any solution to make the arrow move smoothly to the next item without sliding to the left first?

CSS styling for the marker:

#marker {
background: transparent url("http://cdn7.unit4.com/images/theme/2014/icons/down.png") no-repeat scroll 50% 50%;   
height: 16px;
left: 14%;
position: absolute;
z-index: 1;
width: 45px;}

Answer №1

To make the marker move smoothly, you can adjust the script as shown below and incorporate a CSS transition effect. Check out a demo I created HERE using your code along with some random CSS styles

$("#services ul > li").click(function(event){
    var position = $(this).position().left;
    var width = Math.round($(this).width()/2) - 5;
    var arrowPos = position + width;
    $('#marker').css('left', arrowPos);
    event.preventDefault();
});

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

Issues with jQuery Functions Arising After Utilizing .load() to Update div Element Text

After processing form data, I am reloading the content of "#some-div" using the ".load()" function. It successfully refreshes "#some-div" with the updated content. However, the issue I am facing is that none of my other jQuery functions (such as ".some-t ...

I am looking to create a header design that is fully responsive and resembles the example shown in the image. How can I achieve

Currently, I am working on creating a responsive header for a website. The image provided is a rough draft of the header design that I am aiming to achieve. I attempted to form the shape using an SVG path but encountered difficulties in making it fully res ...

Ways to identify if one object is positioned above another

So, here's the scenario: I'm trying to figure out how to detect when one element is positioned on top of another. Specifically, I'm dealing with SVG elements: <circle r="210.56" fill="#1ABCDB" id="01" priority="4" cx="658" cy="386">& ...

Javascript code creates a blur effect on webpage bodies

On my webpage, I have multiple elements, including a "change BG" button. When this button is clicked, I want to hide all other content on the page except for the button using JavaScript. Alternatively, clicking the button could blur out all other elements ...

Experience unique website functionalities across Windows/Android and Apple ecosystems

Apologies for any language errors in advance. I'm facing an issue where my website appears differently on Safari or Chrome on iOS/MacOS compared to Windows 10 or Android devices. If you observe the List of Receiving Countries in the images provided: ...

Issue encountered when attempting to utilize multiple datasets with Twitter Typeahead/Bloodhound

Hello, I am currently learning how to use Typeahead and Bloodhound with the latest javascript. Below is a snippet of my code: Html: <div id="multiple-datasets"> <input class="typeahead" type="text" placeholder="NBA and NHL teams"> </div ...

having difficulty sending an Ajax request to a Json API service

I am looking to make a call to a web service that provides a JSON object. The specifications for the web service can be found at the following link: Within my asp.net mvc3 web application, I have a simple view structured like this: @{ ViewBag.Title = ...

Is there a way to customize the color of a MUI styled component?

I have a customized MUI component that displays a circular badge in green. const StyledGreenBadge = styled(Badge)(({ theme }) => ({ '& .MuiBadge-badge': { backgroundColor: '#44b700', color: '#44b700', ...

When using a jQuery $.ajax request to call an MVC ActionResult that returns JSON data, the .error function will

I am encountering an issue with my $.ajax post call. It seems to trigger the "error" block of the function even before the actionresult completes and also forces a page reload after each pass. var pnameVal = '<%: this.ModelCodeValueHelper().ModelC ...

Are there any CSS3 selectors currently available or planned for matching partial attribute names?

By using [foo^="bar"], you can target nodes with the attribute foo that starts with the value bar. Is there a method to select nodes based on an attribute name that begins with a specific string? This would be useful for selecting all nodes with a data-* ...

Insert comments into MySQL database using asynchronous JavaScript and JSON technology

Looking at the diagram, I have a scenario where two tables exist in my MySQL database and the goal is to enable the system to add and retrieve comments without the need to refresh the page. This functionality involves three PHP pages: 'DB.php', ...

Using jQuery, Ajax, and HTML together can create dynamic

Is there a way to run JavaScript functions in an HTML file that is loaded using AJAX? The HTML file contains both text and JavaScript, but only the inline JavaScript seems to work (like onclick="dosomething();return false"). The pre-defined functions wra ...

Personalizing Google Map pin

I found some code on Codepen to add pointers to a Google map. Currently, it's using default markers but I want to change them to my own. However, I'm not sure where in the code to make this update. Any examples or guidance would be appreciated. ...

Submitting a form using jQuery and processing the response

Can a form be submitted using jQuery without utilizing json, ajax, or other methods for handling the result? For example: <form id="loginform"> //some input fields and a submit button. </form> And then with jQuery: $("#loginform").sub ...

Animate a jumping figure using jQuery

Is it possible to create an animation of a person jumping from the bottom of the screen to the top, with the scroll bar following them? I have my doubts but would love to know if it can be done. If you want to see what I mean, check out this PDF: http:// ...

What is the best method for aligning buttons in a row with all the other buttons?

I have been attempting to display two buttons, id="strength" and id="minion", when a certain button, id="expandButton", is clicked. I want these two buttons to be positioned on either side of the button that triggers their cre ...

Simultaneous execution of PHP form action and jQuery validation

When I try to execute my jQuery validation and PHP form, both actions are happening simultaneously. This means that validation errors are being displayed while the PHP form action is also being executed. Below is the complete code snippet. The jQuery form ...

The concept of length is not recognized within the jQuery library

I'm currently attempting to search for an object's attribute within JSON data. However, I keep encountering an error message stating uncaught type error:length is not defined while using jQuery. Here's a snippet of my JSON data: var list = ...

What steps can I take to decrease the padding of this footer?

Is there a way to reduce the height of the footer so it doesn't dominate the screen on both large and small devices? https://i.sstatic.net/nIQz6.png import { Container, Box, Grid } from "@material-ui/core"; const Footer = (props) => { ...

Load the React chunk CSS dynamically to optimize performance and only when it is necessary

After running an audit, Lighthouse is advising me to "Defer unused CSS" for my React app. Despite implementing code splitting and having separate CSS files for each chunk, the suggestion persists. One particular example highlighted by Lighthouse is the foo ...