Using jQuery to Generate an Automatically Updating Timer for Slideshow - Pausing on Mouse Click

My first slideshow with jQuery is up and running, but it's very basic and hard coded. I want to add an automatic scrolling effect every 8 seconds to the next item before looping back to the beginning.

I have an idea on how to achieve this, but I want to follow best practices in my design

HTML:

<div id="slideWrap">
<div id="slides">
    <ul id="slidePane">
        <li><img src="css/images/slides/slide1.png" alt="img1" /></li>
        <li><img src="css/images/slides/slide2.png" alt="img2" /></li>
        <li><img src="css/images/slides/slide3.png" alt="img3" /></li>
        <li><img src="css/images/slides/slide4.png" alt="img4" /></li>
    </ul>
</div>
<div id="slideNav">
    <ul>
        <li class="active"><h2>Packages</h2></li>
        <li><h2>Portfolio</h2></li>
        <li><h2>Prices</h2></li>
        <li><h2>About</h2></li>
    </ul>
</div>
</div>

jQuery:

<script>
(function() {
var slider = $('#slides'),
        imgWid = $('ul#slidePane img').width(),
        imgHeight = -300,
        imgs = 4,
        imgsHeight = 3200; 

$('#slideNav ul li').on('click', function() {
        var listSel = $(this),
            selImg = $('#slideNav li').index(this);

        $(this).addClass('active');
        $(this).siblings('li').removeClass('active');
        slider.animate({
            'margin-top': imgHeight * selImg
        });
    });
})();
</script>
  • I'm looking for guidance on implementing a feature that allows for auto-scrolling through items vertically until user interaction stops it. *

Live Host:

If you need my CSS code, please let me know although I believe it may not be relevant to the question.

Answer №1

Instead of taking the modern approach, I think I'll stick to the good old-fashioned method of doing it by hand. It may not be the easiest way, but sometimes simplicity is best. I'll share the outcomes here in due time.

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

Ways to retrieve JSON data using Angular JS

I'm currently working on populating my table with data. The URL returns JSON data, but I'm struggling with how to retrieve it using AngularJS. Here is my services.js: angular.module('OrganisatieApp.services', []) .factory('organi ...

Ways to prevent my website from being accessed through the Uc Browser

Is there a way to prevent my website from functioning on UC Browser using HTML or JavaScript? ...

Display my additional HTML content on the current page

Is it possible for my addon to open a predefined html page in the current window when it is started? And if so, how can this be achieved? Currently, I am able to open my addon page in a new window using the following command: bridge.boot = function() { ...

Toggle the visibility of a table row depending on the selected value of a Radio button

I have a jQuery script that I am working on, which toggles the visibility of table rows based on the selection of radio buttons. The current code functions properly when a radio button is clicked, but I would like to enhance it to automatically show or hid ...

If I utilize npm in Visual Studio Code, where can I find the installation location of my

After installing jquery for use, I'm having trouble locating where it's been installed. Where is my jquery file stored and how can I locate it? ...

The jQuery draggable feature ceases to function after it has been dropped

I have a scenario with two divs, each housing a list of quantities and items. These items are draggable, and the div containing them is droppable. The condition here is if an item with the same name exists in the div, it cannot be dropped on that div again ...

Has the jQuery plugin object misplaced a variable?

I am in the process of developing a basic plugin using jQuery. My current approach involves creating private functions and storing variables within the jQuery object itself. (function($) { var somePrivateFn = function() { alert(this.x); } ...

Is it feasible to directly load image objects into jQuery colorbox?

Currently, I am working with the "colorbox" jQuery plugin and I have a specific requirement to dynamically load a set of preloaded image objects into colorbox. The challenge lies in the fact that I have three different image sizes - thumbnail, display, an ...

Fetch real-time server information using the img src attribute

Currently, I am using ajax jQuery to dynamically populate an image src with a value that is retrieved from the server. However, I would like to streamline the code and eliminate the need for the jQuery portion. This is the current setup: Javascript (code ...

PHP - WebCalendar - Show or Hide Field According to Selected Item in Dropdown List

Working with the WebCalendar app found at to make some personalized adjustments to how extra fields function. I've set up two additional fields: one is a dropdown list of counties, and the other is a text field. Within the dropdown list, there is an ...

Is it possible to relocate the HTML components generated by sDom from DataTables?

Trying to relocate my "sDom generated" HTML search component from my datatable using jQuery, like this for example: $("#-filter_form").prepend($("#finder")); I attempted to insert this code right after initializing my datatable and also at various points ...

Optimize your website by reducing the size of CSS, JavaScript, and HTML files through NUXT's

I'm currently working on a project in NUXT utilizing yarn for managing packages. My objective is to compress (and potentially merge) js, css, and html files to enhance load time efficiency. I came across "https://www.npmjs.com/package/nuxt-compress" ...

Design a layout consisting of a grid with items that maintain a set maximum width while being evenly distributed across the entire width of the device

I'm trying to create a grid with 2 rows and 3 columns, each cell having an image with a max-width of 512px. I added margin to the grid but now the cells are larger than the content. How can I achieve the same visual appearance as flexbox's justif ...

Having trouble encoding PHP array in jQuery

I am struggling to find the index in a JSON array. The browser is displaying undefined data. I have posted the code snippets below. Here is my PHP encoded array: [{"voo_Cod":"1","voo_CidadeOrigem":"1","voo_CidadeDestino":"2","voo_Data":"2015-07-13 07:00: ...

Issues with loading CSS, JavaScript, and links when deploying a Spring Boot application as a WAR file in Tomcat

My Spring boot web application runs smoothly as an executable jar, but when I build it as a war and deploy it to Tomcat, the CSS and JS files fail to load. Upon further investigation, I discovered that all links are pointing to the root context path "/" I ...

Add a border to the element if its height exceeds 300 pixels

My web page has a dynamic element with an unpredictable height. As more content is added, the element grows, but I have restricted it with a max-height: 300px;. However, I would like to add a hint to the user when the element reaches its maximum height by ...

Center text within a span element

I'm struggling to set up arrow navigation with both next and previous buttons that need to function in Internet Explorer 7 and newer versions. For the next button, I want the background image to appear to the right of the text. As for the previous bu ...

Error encountered while sending AJAX request with JSON data type

Is it possible to submit a Form using ajax with the jsontype? Suppose I have 5 fields in the form, where 4 of them are normal textboxes and one field contains JSON. When trying to send this data via ajax, an error is thrown. How can I resolve this issue? ...

Numerous Kendo windows are layered on top of each other, yet the text divisions within them remain distinct

I am currently working on a project that involves laying out multiple Kendo windows in rows. Specifically, I need to display 4 windows in each row and have them shift left when closed. My framework of choice is Bootstrap 3. Everything works as expected w ...

How to Efficiently Organize OpenAI AI Responses Using TypeScript/JavaScript and CSS

I'm using a Next.js framework to connect to the OpenAI API, and I've integrated it seamlessly with an AI npm package. The functionality is incredible, but I've encountered an issue regarding line breaks in the responses. You can find the AI ...