Ride in a way that involves pausing at regular intervals

Struggling to grasp the basics of web design, particularly HTML, CSS, and JS/JQuery. Encountering obstacles that seem insurmountable.

I'm attempting to rotate a few divs on my page with limited success. My makeshift solution involves toggling between hidden divs, but it's far from elegant. Strangely enough, it only works twice before hitting a roadblock.

function moveSide(){
    var intervalId;
    var childCount = 2;
    var preLast = childCount + 2;
    var newLast = childCount + 3;

    intervalId = setInterval(function () {
        $(".column:nth-of-type(" + childCount + ")").toggle("slide", function(){
            $(".column:nth-of-type(" + preLast + ")").removeClass("last").delay(1, function(){
                $(".column:nth-of-type(" + newLast + ")").addClass("last").delay(1).toggle("slide", function(){
                    childCount++;
                    preLast = childCount + 2;
                    newLast = childCount + 3;
                    //alert(childCount);
                });
            });
        });
    },5000);
}

The nth-of-type selector may not be the best choice, but it helps me target specific divs. childCount determines which div is toggled first, preLast identifies the last displayed div for relevant class removal, and newLast assigns properties to the next visible div.

The alert cycle completes two rotations before faltering on the third. Any insights into where I might be going wrong?

Answer №1

Maybe it's just my lingering cold or the fact that I've only been up for a few hours, but I'm having trouble understanding your code.

I grasp the goal you're aiming for, and I have a different approach to suggest:

$(".column:gt(0)").hide(); // Start by hiding all columns except the first one

setInterval(function() { 
$('.column:first')                     
  .toggle("slide")                    
  .next().next()                      
  .toggleClass("last")               
  .next()                            
  .toggleClass("last")              
  .toggle("slide")                
  .end().end().end()             
  .appendTo('#column-content');   
}, 5000);

Your interval should now be running endlessly - sliding out the first element, bringing in the next element, and moving the first element to the end. This way, the current element always remains the first one... check out the fiddle here: http://jsfiddle.net/sv5j85df/2/

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

scraping text content from a CSS node using Scrapy

My goal is to extract a catalog ID number from the following webpage: from scraping.selector import Selector from scraping.http import HtmlResponse url = 'http://www.enciclovida.mx/busquedas/resultados?utf8=%E2%9C%93&busqueda=basica&id=& ...

Translating language in jquery date selector

Is there a way to combine language translation with changeMonth and changeYear options in jQuery datepicker? I have tried the following code: $(this).datepicker($.datepicker.regional['fr']); And for ChangeYear: $( this ).datepicker({ cha ...

Customizing time choices for angular-jquery-timepicker

I am incorporating the angular-jquery-timepicker library from Recras to enable time selection in my Angular application. The time options are currently being generated automatically, but I would like to manually set the options by removing some of them. Fo ...

How can I deselect the 'select-all' checkbox when any of the child checkboxes are unchecked?

Here is the code provided where clicking on the select-all checkbox will check or uncheck all child checkboxes. If any child checkbox is deselected, the 'select-all' checkbox should also be unchecked. How can this be achieved? $(document).read ...

Tips on eliminating excess space between the header and main body of content

I am currently using Bootstrap for my website design. I have placed my content inside a wrapper, with the header positioned outside of it. However, there is a white gap that stretches across the entire page between the nav bar at the top and the right edge ...

Ensuring a user is subscribed to premium when initiating a bot using node.js and telegraf.js

I've been attempting to retrieve the information on whether the user has a premium subscription, however it's not functioning as expected. Do you happen to know the solution to this issue and can assist me with it? ...

Inquiry about Date and Time Selection Tool

I am working on a PHP project that includes two textboxes: one for selecting dates and the other for choosing a specific time. What I need assistance with is disabling any times before the selected date in the second timepicker textbox if today's dat ...

Angular onscroll event creating a parallax effect

I attempted to create a parallax effect using Angular and the OnScroll event, however, while scrolling, the text seems to be flickering. Is there a way to make the smooth rendering onscroll? Maybe through CSS alone? Here is the script I used: https://sta ...

Load MP3 or MP4 files upon initial loading

I am trying to automatically play an MP3 audio file as soon as my page loads, ideally using JavaScript. The audio should only play once and at the beginning Despite referencing W3Schools and Mozilla documentation on the audio element, I couldn't get ...

JavaScript jQuery not starting up

Having issues with the jQuery Vertical Accordion from Design Chemical Menu not loading properly. I'm new to jQuery and struggling to get it working as intended. The plugin isn't displaying the accordion menu, just plain lists. Even though testin ...

Sinon experiences delays during an AJAX call

I am working with Mocha Chai and Sinon to test a revealing module pattern and encountering a timeout failure. How can I effectively test a method that assigns variables from an AJAX request? Test.js (function () { 'use strict'; describe(&a ...

Get Angular events in the proper order

I am currently facing challenges with event handling in AngularJs. In my service, I send out events using the following line of code : $rootScope.$emit("FNH."+this.status, flowNodeHelper); When receiving the event in service "S1," I handle it as follows ...

Seeking out and showcasing a distinct item from an array in MongoDB - how can it be done?

I'm struggling with writing a mongo script for my app to retrieve and display the service logs for a specific vehicle. In this case, I have two users, each with multiple vehicles that have their own set of service logs. Despite my efforts, I haven&apo ...

Utilizing AJAX for creating content in the background?

When using imagejpeg() to create images, I've noticed that they take longer to render than the time it takes for the page to load. As a result, the images either don't display properly or are cut off. I've attempted to delay the page loadin ...

Placing divs in rows and columns at specific breakpoints

I have a footer with two divs that I need to be centered and side by side. When the screen size reaches 960px, I want the second div to move below the first one while still staying centered. Does anyone know how to achieve this? Below is my code snippet: ...

Switch out HTML dynamically using JavaScript/JQuery, embracing the principles of DRY coding

As a newcomer to front-end development, one issue I frequently encounter is avoiding repetition when dynamically generating HTML using JS/jQuery. Imagine you have a DOM object that has various states. Typically, all you need to do with JS is switch betwee ...

Having trouble submitting a date input form generated with vuejs on Safari browser

I am a huge fan of Vuejs and it's my go-to at work. The other day, I came across a rather perplexing scenario. If you have any insights into this, please do share. Here is the code in question: <script setup lang="ts"> import { ref ...

Eliminate redundant items within an array by comparing their unique identifiers and dates

I am looking to eliminate duplicate object entries based on id, while displaying the most recent object entry based on pubDate. Take a look at my example array below: var arr = [ {fileID: "1234", pubDate: "04/13/2018", id: "49791 ...

What is the best way to display a static HTML file using Handlebars on a Node.js server?

I have been searching online for resources on this topic, but I haven't found one that simplifies the concept enough for me to grasp. Currently, my HTML document contains multiple large <script> tags with handlebars content. This HTML file is s ...

Show the date using Roman numerals

I'm looking to showcase the current date on my website using jquery or javascript, which seems like a simple task, right? However, I want the date to be presented in roman numerals (d/m/y format). For example, instead of 13/10/2013, I would like it d ...