Animation will cease once the page is refreshed via Ajax

I'm facing a challenge with a problem that I can't seem to resolve. The issue lies in my use of this plugin for displaying random images.

The only step left is to refresh the content within the div. However, every time I attempt to do so, the animation comes to a halt! It simply ends up showing pictures stacked on top of each other without any animation.

Here's the code snippet responsible for the refresh:

<script>
    var auto_refresh = setInterval(function () {
        $('#updatepic').load('updatepicx.php');
    }, 5000); 
</script>

<div id="updatepicx"></div>

If I manually execute updatepicx.php, it works perfectly fine. But whenever I try to integrate this into the index.php for automatic refreshing, the animation stops working altogether.

Where could the problem possibly lie?

This is the code from updatepicx.php:

<?php include('core/init.php');
include('includes/article.php');?>
<?php


$article = new Article;
$articles=$article->fetch_all4();

$categorie = new Article;
$categories=$categorie->fetch_allonecategorie();

$image = new Article;
$images=$image->fetch_all6();


?>

<!-- Numerous JavaScript and CSS script references follow here -->

<div id="carousel">
 <?php foreach  ($images as $image){ 
 $title='<font color=red>name:</font>'.$image['article_title'].''.str_repeat('&nbsp;', 40).'
 <font color=red>categorie:</font>'.$image['categorie'].''.str_repeat('&nbsp;', 20).'
  <a  style=text-decoration:underline; href=article.php?id='.$image['article_title'].'><font color=#0086D2>view</font>';
 ?>

    <a href="imagecible/<?Php echo $image['image'];?> "title="<?Php echo $title;?>" rel="imagebox" ><img class="imgfx" 
    src="imagecible/<?Php echo $image['image'];?> " width="100%"></a>
 <?Php }?>
    </div>
<script type="text/javascript">
    window.onload = 
        function()
        {
            $('#carousel').Carousel(
                {
                    itemWidth: 110,
                    itemHeight: 62,
                    itemMinWidth: 50,
                    items: 'a',
                    reflections: .5,
                    rotationSpeed: 1.8
                }
            );
            $.ImageBox.init(
                {
                    loaderSRC: 'images/loading.gif',
                    closeHTML: '<img src="images/close.jpg" />'
                }
            );
        };
            $(document).ready(function() {

        $("#Imx").on("click", function () {

        $("#ImageBoxContainer").hide();
            })

    });
</script>


<div id="cAssistentHelper" style="position: absolute;z-index: 9999"></div>
<div id="ImageBoxOverlay" style="position: absolute; top: 0px; left: 0px; opacity: 0; height: 705px; width: 1366px; display: none;"> </div>
<div id="ImageBoxOuterContainer" style="position: absolute; overflow: hidden; top: 47px; left: 0px; text-align: center; width: 1366px; display: none; background-color: transparent;">
<div id="ImageBoxContainer" style="position: relative; overflow: hidden; text-align: left; margin: 0px auto; top: 0px; left: 0px; z-index: 2; width: 52px; height: 52px;">
<img src="images/loading.gif" id="ImageBoxLoader" style="position: absolute; left: 10px; top: 10px;">

</div><div id="ImageBoxCaption" style="position: relative; text-align: left; margin: 0px auto; z-index: 1; visibility: hidden;">
<div id="ImageBoxCaptionText" style="padding-left: 10px;">Flash lights</div>
<div id="ImageBoxCaptionImages" style="padding-left: 10px; padding-bottom: 10px;"> 
</div><a id="ImageBoxClose" href="" style="position: absolute; right: 10px; top: 0px;"><img id="Imx" src="images/close.jpg"></a></div></div>

Answer №1

Make sure to reapply the plugin after replacing the div with new elements that are not connected to the plugin. Include this snippet in your code:


var auto_refresh = setInterval(function () {
    $('#updatepic').load('updatepicx.php',function(){ 
       // Apply the plugin after successful load
       $('#carousel').Carousel(
            {
                itemWidth: 110,
                itemHeight: 62,
                itemMinWidth: 50,
                items: 'a',
                reflections: .5,
                rotationSpeed: 1.8
            }
        );
    });
}, 5000);

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

Enabling the acceptance of blank values within an HTML5 date input field

When using an HTML5 date input for a field that corresponds to a nullable datetime column in the database, how can one avoid setting an empty value in the input field? In my AngularJS application, the ng-model is connected to a scope variable with an init ...

Tips for preventing the loss of ajax calls when an Oauth access-token expires

As the creator of a JavaScript browser application (SPA) that communicates with a server protected by OAuth 2, I encounter the challenge of using short-lived access tokens and longer-lived refresh tokens. While this specific scenario involves my own server ...

Employing on() for triggering a form submission

I am attempting to attach a submit event handler to a form that may not always be present in the DOM, so I am using .on(): $('body').on("form","submit", function(e){}) However, when checking Firebug, it shows: $("body").on is not a function ...

"Troubleshooting a matter of spacing in HTML5 body

I've been struggling to eliminate the gap between the top of my webpage and the <div> element. Here's the code snippet causing the issue: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="v ...

fill the designated column in accordance with the specific criteria

Is there a method to automatically fill in a specific column based on certain conditions? I am looking to populate the column labeled [Last] when the column index is 1 and the corresponding name is [First]. import {Component, OnInit} from '@angular ...

using JavaScript to strip away content following .jpg

var lochash = "#http://www.thepresidiumschool.com/news_image/102%20NRD_7420.jpg&lg=1&slide=0"; I am looking to eliminate or modify the content that comes after .jpg. ...

Implementing Ajax functionality in Ruby on Rails

I wish to send the selected drop-down menu value to a controller using ajax panel_controller.rb class PanelController < ApplicationController def insert @selected_city_ids = params[:city] end panel.js.erb $(document).ready(fun ...

Checking validation with parsley.js without triggering form submission

I have been working with the latest release of Parsley for data validation. While it is validating my data correctly, I am encountering an issue where the form does not submit after validation is complete. I have spent hours trying to troubleshoot this pro ...

Applying styled text to a Node.js chat application

I developed a chat application using node.js which allows users to enter a username and send messages. The messages are displayed in a <ul> format showing "username: message". I was looking for a way to make the username appear bold and in blue color ...

Function defined as an AngularJS component

I am facing an issue where my component is not initializing when I create it with a function that returns a component object. Can someone please help me understand the difference between these two situations? Html: <div ng-app="demoApp"> <navb ...

Exploring HTML Data with Python String Manipulation

My goal is to use Python to dynamically extract data from an HTML page that is constantly changing. I have identified that the specific data I am interested in is located between a tag that resembles 'abcd>' and another tag. For example: abcd& ...

More efficient methods for handling dates in JavaScript

I need help with a form that requires the user to input both a start date and an end date. I then need to calculate the status of these dates for display on the UI: If the dates are in the past, the status should be "DONE" If the dates are in the future, ...

Fill your HTML form effortlessly using data from Google Sheets

I am relatively new to this topic, but I'm seeking a solution to populate an Apps Script Web App HTML dropdown form with names directly from a Google Spreadsheet. At the moment, I've managed to retrieve an array of names from column A in my sprea ...

"Creating visual art with processing in 2D using P5

Recently, I came across a webpage about rendering 2D objects in processing using JavaScript. Here is the link to the page: Upon trying out the example code provided on the page in a new P5 project, I noticed that the code structure looked like this: HTML ...

Change the <base> element programmatically during server-side rendering

Searching for a way to obtain the base URL for an HTML page, so that relative URL requests from the browser utilize that base. If you are looking for answers, check out this link: Defining root of HTML in a folder within the site root folder When serving ...

Adjust the height of a div in JQuery to fit new content after specifying a height previously

I have a division element with an initial height of 0 and opacity set to zero, its overflow is hidden, and it contains some content. <div style='height: 0px; opacity: 0px; display: none; overflow: hidden; border: 1px solid #000;' id='myd ...

Tips on efficiently rebinding jQuery events to dynamically loaded content without having to manually do it for each event or class

Recently, I encountered an issue with my jQuery app where I needed to bind different functions to elements within one div dynamically. Specifically, I had a "delete-function" attached to all ".btn-delete" elements and an "add-function" linked to all ".btn- ...

Trouble with the JQuery event listener onchange()

On my webpage, I've set up a drop-down list and a text-box in the following HTML code: <table> <tr> <td>Group Name: </td> <td><%= Html.Dr ...

Enhanced auto-zoom feature with orientation change for iOS 7

My web page was functioning perfectly until the release of iOS 7 by Apple today, causing the layout to break when the screen orientation is changed. When focusing on a text area and rotating the screen to landscape view, the entire page zooms in. However, ...

Troubleshoot: Bootbox Confirm Functionality Issues

Can anyone help me troubleshoot this issue? I'm trying to implement code that uses bootbox.confirm when deleting a file, but it's not functioning correctly. $('#fileupload').fileupload({ destroy: function (e, data) { var that = $(th ...