Following the content update via Ajax, the functionality of jQuery is experiencing glitches

My content slider works well on the first page of ajax loaded content. However, when I navigate to the next page from ajax loaded content and try to update the sliding animation for newly loaded future content using #readyslider, the slider starts glitching. The timing and fade events start malfunctions. Why is this happening?

As I continue to the next pages, the slider problems worsen.

I've searched online and tried various solutions including using jQuery noConflict method but to no avail. Here's an example:

I attempted replacing all instances of $ with j using jQuery noConflict like so:

Unfortunately, this did not resolve the issue.

EDIT : I have provided the entire HTML and CSS code for my slider. Try clicking the ReadySlider button multiple times to see the problem.

My Approach:


var j = jQuery.noConflict();
j(document).ready(function () {

j(document).on("click", '#readyslider', function(event) { 
    setTimeout(function () { 

var interval;
var interval = false;
j("#subttlslider > div:gt(0)").hide();

function updateDiv() {
  j('#subttlslider > div:first')
    .fadeOut(600)
    .next()
    .fadeIn(400)
    .end()
    .appendTo('#subttlslider');
}

j("#nextclick").click(function(){

    $('#subttlslider > div:first-child')
    .fadeOut(600)
    .next()
    .fadeIn(400)
    .end()
    .appendTo('#subttlslider');
});

j("#prevclick").click(function(){
    $('#subttlslider > div:first-child')
    .fadeOut(0)
     $('#subttlslider > div:last-child')
    .prependTo('#subttlslider') 
    .fadeOut();
    $('#subttlslider > div:first-child').fadeIn();
});


j(".play").click(function() {
  if(!interval){
    interval = setInterval(updateDiv, 5000);
  }
  

});

The original code for my slider is:

$(document).on("click", '#readyslider', function(event) { 

    setTimeout(function () { 

var interval;
var interval = false;
$("#subttlslider > div:gt(0)").hide();

function updateDiv() {
  $('#subttlslider > div:first')
    .fadeOut(600)
    .next()
    .fadeIn(400)
    .end()
    .appendTo('#subttlslider');
}

$("#nextclick").click(function(){

    $('#subttlslider > div:first-child')
    .fadeOut(600)
    .next()
    .fadeIn(400)
    .end()
    .appendTo('#subttlslider');
});

$("#prevclick").click(function(){
    $('#subttlslider > div:first-child')
    .fadeOut(0)
     $('#subttlslider > div:last-child')
    .prependTo('#subttlslider') 
    .fadeOut();
    $('#subttlslider > div:first-child').fadeIn();
});


$(".play").click(function() {
  if(!interval){
    interval = setInterval(updateDiv, 5000);
  }
  

});

$(".pause").click(function() {
  clearInterval(interval);
  interval = false;
});

    }, 10);

});
#subttlslider>div {
  position: absolute;

}
... (CSS styles omitted for brevity) ...
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
... (HTML and buttons omitted for brevity) ...

<div id="subttlslidermaindiv">
<div id="subttlslider" class="detailcontainer">
<div class='slideInLeft'>1) There is a lot of stress around us whole day which creates lot of hindrance in our mind.

... (more slider content omitted for brevity) ...

</div>

It seems that the problem arises from injecting the slider code repeatedly by clicking on the #readyslider button when my ajax content updates...

I'm unsure about the alternative solution to ensure the slider runs smoothly each time after navigating to ajax-loaded content without any glitches.

Any assistance on this matter would be greatly appreciated! Thank you in advance :)

Answer №1

Is there a way to limit its activation to just once?

let triggered = false;       // Updated
$(document).on("click", '#readyslider', function (event) {
    if (!triggered) {        // Updated
        triggered = true;    // Updated
        setTimeout(function () {
            // ...Same...
        }, 10);
    }
});

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

Attempting to set up an Ajax webform with various outputs, but encountering issues with functionality

I'm encountering an issue while creating interactive exercises. I want to display correct or incorrect answers immediately after submission using JSON for retrieving responses, as suggested in a forum. However, my AJAX code isn't working at all. ...

Trigger the fire event on .click() except when text is being selected

I am currently working on a chat box project and I want the input field within the message area to automatically get focused when the user clicks anywhere in the chat box. However, I don't want this functionality to interfere with text selection for c ...

Tips for efficiently updating state within a loop using the settimeout function in a React application

As I work on my react app to visualize sorting algorithms, I've encountered an issue that has me stumped. I am currently iterating through all elements of the array stored in the 'bars' state and attempting to swap them for testing purposes. ...

Tips for sending an array to an action method in ASP.Net MVC

Currently, I am working on an ASP.Net MVC5 project where I am attempting to send JSON data to the controller's action method via an AJAX request. The JSON data consists of various form values. To facilitate a master-detail form structure with one-to-m ...

MUI Autocomplete causing a never-ending cycle of requests

One of the challenges I'm facing involves an Autocomplete component in my code. Here's a snippet of the code: <Autocomplete filterOptions={(x) => x} options={items} getOptionLabel= ...

Is there a way for me to manage the rendering of a three.js scene?

I've noticed that most examples use a loop structure to render the scene, like so: renderer.render(scene, camera); function render(){ renderer.render(scene, camera); //code for rendering requestAnimationFrame(render); } render(); Howev ...

Unable to activate check box button by clicking on it

Hi there! I am having trouble with a checkbox button on my website. The button appears fine, but for some reason it's not working properly (it doesn't get unchecked when clicked). Can anyone help me fix this issue? I'm still learning HTML an ...

Quantifying the passage of time for data entry

Looking to create a quiz form where I can track how long it takes users to input/select answers. I attempted the following code but the timing seems off: $('input, select').on('focus', function(event) { el = $(this); name ...

Exploring jQuery: Implementing a SlideDown Effect on Loading Questions

Greetings, this is my debut post on stackoverflow. I have been an avid reader and learner here. I am currently using a jQuery function to load posts in WordPress themes using the .load function. However, I am facing a challenge that I cannot resolve on m ...

Printing keys of objects in an array in AngularJS through iteration

Here is an array of objects that I am attempting to iterate in ng-repeat and print keys, but I am facing some challenges. $scope.directivesInfo = [ {"ngRepeat": {"enter": true, "leave": true, "move": true, "add": false, "remove": false}}, {"ngView ...

Utilize only certain JSON properties within JavaScript

I have access to an array of JSON objects. [ { Id: "1", StartNo: "1", ChipNo: "0", CategoryId: "0", Wave: "0", Club: "", FirstName: "Lotta", LastName: "Svenström", FullName: "Lotta Svenström", ZipCode: "24231" }, {...} ] My goal is to create a new data ...

The Bootstrap Input-Group with Spinner displays an unusual spinning shape that resembles the letter D

I am encountering an issue with a unique form that sends each line of input as a separate request upon submission. I am looking to add a spinner at the end of each line, but I am facing a problem where instead of a circular spinner, I am getting a spinning ...

Creating dynamic forms using AngularJSIn this tutorial, we will explore how to generate

I need help creating an HTML form. I have an object that stores an array of form elements like { "formFields": [ { "type": "select", "label": "Fabric", "name": "fabric", "options": [ ...

Error message encountered: "myData undefined while executing server in Node.js"

const express = require('express'); const app = express(); app.post('/', (req, res) => { let newData = new contact(req.body); newData.save() .then(() => { res.send("Data has been successfully saved to ...

What is the process for invoking a page using a JavaScript function?

My index.php has a javascript code that calls a page in the following way: id = 5; var url = 'pages/pg/'+id+'/'; f.action = urlss.toLowerCase(); return true; The issue arises when I try to call the same page with a different ID, it do ...

Unable to access this context in Firefox debugger after promise is returned

I'm curious as to why the 'this' object is not showing up in the debugger in Firefox, but it does appear in Chrome's debugger. When I try to access 'this.myProperty', it shows as undefined. This is the code from my TypeScript ...

Using Jquery to send dynamic id and base url to a Laravel route

I have a jQuery script that uses AJAX to update the rating for a contest and sends the data to a controller to make changes in the database. My challenge is figuring out how to dynamically retrieve the contest ID and base URL of the website from the curre ...

Tips for connecting to multiple items in an md-select element from within a directive

Looking to develop a straightforward directive that displays either a textbox or dropdown based on whether an array is provided for the model property on the scope. Any value other than explicitly setting false in the directive markup such as multiple="fa ...

Deactivating Touchable Opacity Sounds in React Native

Currently, I am in the process of developing an application, utilizing TouchableOpacity instead of a button. I am looking to disable the auditory feedback that occurs when the TouchableOpacity component is pressed. <TouchableOpacity activeOpacity={1} to ...

The alignment of the text with the Bootstrap glyphicon is off

Currently, I am in the process of developing a form and implementing validation on my bootstrap form using bootstrap components. To handle server side validation, I am utilizing a c# class library, and then using c# code-behind to apply styles when the for ...