The Seamless Experience of a Never-ending Carousel Menu

I'm currently working on a website at

The top menu on this site should scroll when hovering over arrows, but it only moves once with hover. I would like it to keep moving infinitely until the mouse is removed from the area.

How can I achieve this effect? I tried using a carousel, but without success.

Additionally, there are some "hiccups" in the movement, possibly due to timing. How can I make the scrolling smoother?

<div class="row-fluid" style="position:relative;">
        <div class="span12 horizontal-category" style="height: 64px">                                 
          <span class="carousel-prev" id="carousel-category-prev"></span>
          <div class="j" style="position: absolute; clip: rect(auto, auto, 500px, auto);">
              <ul class="nav myCustomNav">       
                <?php
                    printCats();
                ?> 
               </ul>
          </div>
          <span class="carousel-next" id="carousel-category-next"></span>                                   
        </div> 
    </div>

<script>

        $(document).ready(function(){
            $(".myCustomNav li:first").addClass("current");
            $(".myCustomNav li:last").addClass("last");
            $(".last a").width(120);
            carousel();
        });

        var vel = 350;
        var timer;

        function carousel(){                
            $(".carousel-prev").hover(function(){
                timer = setInterval(hover_esquerda, vel);
            }, function(){ clearInterval(timer); });

            $(".carousel-next").hover(function(){
                timer = setInterval(hover_direita, vel);
            }, function(){ clearInterval(timer); });        
        }

        function hover_esquerda(){
            //move left
            if ($(".current").size() == 0){
                $(".myCustomNav li:first").addClass("current");
            }
            if ($(".current").nextUntil(".last").size() == 6){

                //$(".carousel-prev").addClass("disabled");

            } else {                
                $(".myCustomNav .current").removeClass("current").next().addClass("current");
                $(".myCustomNav").animate({
                    left: '-=' + $(".current").prev().width()
                }, 'slow');
            }
        }
        function hover_direita(){
            //move right               
            $(".myCustomNav .current").removeClass("current").prev().addClass("current");
            $(".myCustomNav").animate({
                left: '+=' + $(".current").width()
            }, 'slow');
        }

    </script>

Answer №1

If you want to eliminate the 'hiccups' in your animation, try setting the easing to 'linear'. This will result in a smoother animation compared to the standard 'swing' easing, which causes acceleration and deceleration.

$(".myMenu").animate({
                            left: '-=' + $(".active").prev().width()
                          }, 'slow', 'linear');

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

Creating a 2x2 grid layout with flexbox styling

Having trouble creating a customized 2 by 2 grid using flexbox at the moment. Here is my goal: https://i.sstatic.net/uiGOD.png The height of 1 and 2 should be smaller than 3 and 4. And the width of 1 and 3 should be wider than 2 and 4. I attempted to a ...

Can one ascertain the cleared Kendo grid column filter using jQuery?

I am working with a kendo grid that has approximately 10 to 12 columns, each with its own filtering option. My current task requires me to identify when a column filter is cleared and determine which specific column triggered the event. Is there an event w ...

Exploring an unusual HTML structure using Python's Beautiful Soup and urllib for web scraping

While extracting data may not be a challenge, the real issue lies in locating it. My focus is on scraping football data from a website that presents statistics either for all years or for specific seasons. However, despite selecting a particular season, ...

fuel ux checkbox mark all

I am having trouble implementing a feature where all checkboxes are selected when clicking on a specific checkbox. <div class="checkbox" id="myCheckbox2"> <label class="checkbox-custom" data-initialize="checkbox"> <input class="sr-onl ...

What is the best way to include a dropdown menu in a vertical navigation bar?

Seeking your expertise in creating a dropdown list for my vertical navbar. Any ideas on how to achieve this? I have been exploring various code options for my project. Here's a snippet of what I've tried: https://i.sstatic.net/crSIO.png Here i ...

Guide to fetching React into background.js of a Chrome extension

I'm trying to implement reactDOM for injecting content onto a webpage. Here is the code snippet I have: import React from 'react'; ... import App from './src/js/App'; const root = createRoot(document.getElementById('title&apo ...

Submit files via AJAX with an upload form

I'm facing an issue with uploading a file and saving it on a server using jQuery AJAX. I attempted the process but encountered some difficulties. The file doesn't seem to be processed correctly. Here's what I've been doing: HTML Code ...

Unusual Behavior of HTML Email in Outlook Platform

Hello everyone! I've encountered a simple HTML table issue in an email where the last cell in thead/td is not displaying the background color - it's coming out as white. I'm completely stumped as to why this is happening, as it only seems t ...

Can you explain the extent to which JavaScript's setTimeout() and clearTimeout() apply?

Approximately 30 seconds after a page is loaded or reloaded, a pop-up will be displayed under certain conditions. The following code successfully achieves this functionality: jQuery(document).ready(function($) { .......... if (localStorage.getItem ...

Tips for incorporating a button role into a custom element within an Angular application to improve accessibility for screen readers

I have a unique feature in my Angular application that deals with image handling. The alt text is set as an input to the element and the screen reader is able to retrieve it correctly. However, when I navigate to the image using the tab key, the screen rea ...

Tips for modifying line spacing in R Shiny?

I want to adjust the line spacing in a specific actionButton() displayed in a Shiny App, as shown below and with the MWE code provided at the end. How can I change the line spacing between lines? This adjustment should only affect this action button and n ...

Prevent dragging events while clicking on a link

Recently, I encountered a drag event over an attached div.image element. Whenever I click and hold the mouse down on the div, the drag event initiates. In order to achieve this functionality, I utilized the nestable.js plugin. However, I am facing a chall ...

Handling RxJS ReplaySubject

I'm encountering an issue with a specific template I'm using in Angular 4. The template includes a notification system where new notifications can be added, but the documentation doesn't clarify how one can delete elements from the observer ...

Adding a detached <li> element to a <ul> list: step-by

I am currently facing an issue with adding a li element after deleting it from a ul list. I have experimented with various methods using append() and appendTo() but to no avail. https://jsfiddle.net/kq1yyoLk/ The main concept is that when you click on ite ...

Internet Explorer and jQuery's .val() function work in tandem to

After testing the script below in IE, I noticed that when I click on the input, the cursor moves to the beginning of the input field. [texttext{I click here}ext ] --> [{cursor goes here after click}texttextxt ] $(".chrome-input").focus(function ...

Making ASP.NET textbox wider to fit entire row using bootstrap css

This is my first time working with ASP.NET and I must admit, my HTML skills are still pretty basic. Currently, I am using the Bootstrap grid system to create a form that follows this structure: <div class="container"> <div class=" ...

Issues arise with animated content when viewed on browsers other than Chrome

After coding some jQuery, I noticed that the animation is working properly in Chrome but not in IE (version 11.0) or Firefox (32.0.3). Additionally, I found that if I omit 'opacity: 1;' from my animation class, the element will revert back to it ...

Tips for ensuring a file has downloaded correctly

For my current project, I have a requirement to download a file which should be automatically deleted after being successfully downloaded. To ensure that the file is completely downloaded before proceeding with deletion, I initially set async:false in the ...

Retrieve the ancestors of a specific element within a deeply nested object

Storing data in a variable is very common, and this time we have it as follows: let categories = [ { name: "a", nodes: [ { name: "aa", nodes: [ { n ...

NextJS function utilizes its own references within React and automatically fetches data without the need for an import

I recently purchased this template and I'm trying to figure out which page the code snippet "{getLayout(<Component {...pageProps} />)}" is directed to during the initial load. It seems like it might be a global variable hidden somewher ...