Slider initialization will commence once the slides have been successfully appended

I've been struggling with a jQuery slider that should load after a series of animations finish. Even though I'm appending slides to the slider and trying to initialize it, the slides end up stacking vertically instead of sliding horizontally. My hunch is that when I call $('.slider'), it's empty at that moment. You can see an example here.

The slider container:

<div class="slider"></div>

The slides being added:

var img = $("<img src='http://placehold.it/1042x222&text=1' />");
var img2 = $("<img src='http://placehold.it/1042x222&text=2' />");

The part of my script that appends the slides and calls the slider:

<script src="http://www.ctsciencecenter.org/js/sss.min.js"></script>
<script>
$('.sense1, .sense2, .sense3, .sense4, .sense5, .galatext, .galatext2, #gala5').delay( 800 ).fadeOut( "slow", function() {
$(".slider").append(img,img2);
$('.slider').sss();
});
</script>

This issue has been puzzling me for a while now, so any help or insight you can provide would be greatly appreciated. Thanks for your time.

Answer №1

Behold, the source code at your disposal!

<script>$('#gala5').addClass('animated slideInLeft');$('#gala5').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',function(){$('.sense1').removeClass('offcanvas')
$('.sense1').addClass('animated slideInLeft')});$('.sense1').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',function(){$('.sense2').removeClass('offcanvas')
$('.sense2').addClass('animated slideInLeft')});$('.sense2').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',function(){$('.sense3').removeClass('offcanvas')
$('.sense3').addClass('animated slideInLeft')});$('.sense3').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',function(){$('.sense4').removeClass('offcanvas')
$('.sense4').addClass('animated slideInLeft')});$('.sense4').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',function(){$('.sense5').removeClass('offcanvas')
$('.sense5').addClass('animated slideInLeft')});$('.sense5').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',function(){$('.sense1, .sense2, .sense3, .sense4, .sense5, #gala5').removeClass('offcanvas').addClass('animated slideOutLeft')
$('.galatext').removeClass('offrcanvas').addClass('animated slideInRight')});$('.galatext').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',function(){$('.galatext2').removeClass('offrcanvas').addClass('animated slideInRight')});$('.galatext2').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',function(){$('.sense1, .sense2, .sense3, .sense4, .sense5, .galatext, .galatext2, #gala5').delay(800).fadeOut("slow",function(){$(".slider").append(img,img2);})
$('.slider').sss();});</script>
<script type="text/javascript" src="http://ctsciencecenter.org/wp-content/cache/minify/000000/yyrWLy4u1svNzAMA.js"></script>

wp-content/cache/minify/000000/yyrWLy4u1svNzAMA.js
is identified as sss.min.js

The script sss.min.js is being summoned after its required usage within your code.

Necessitate loading all supplemental scripts beforehand and employ jQuery's DOM ready wrapper $(function(){ ... }); to ensure seamless execution of your script once everything is loaded.

<script type="text/javascript" src="http://ctsciencecenter.org/wp-content/cache/minify/000000/yyrWLy4u1svNzAMA.js"></script>
<script>
    $(function(){
        $('#gala5').addClass( ... etc etc .. 
    });
</script>

While it may suffice with just one or the other, incorporating both practices is recommended for optimal performance.

Answer №2

$(".carousel").append(image1, image2).queue(function() {
    $('.carousel').slideshow();
});

Make sure to include this within $('document').ready( .. )

Answer №3

View my code on jsFiddle

JavaScript Code:

var img, img2, imagesSize = 2;
$( function() {
    img = $( "<img src='http://placehold.it/1042x222&text=1' />" );
    img.load( imgLoaded );
    img2 = $( "<img src='http://placehold.it/1042x222&text=2' />" );
    img2.load( imgLoaded );
} );
function imgLoaded() {
    imagesSize--;
    if ( imagesSize == 0 ) {
        $( ".slider" ).append( img, img2 ).sss();
    }
}

It's advisable to wait for all images to be loaded before proceeding.

Update:
Give this a try:

`jQuery( ".slider" ).sss();`  

Your sss seems to be loading strangely... It appears there is no $.fn.sss, but jQuery.fn.sss does exist. It's possible that something is overriding the jQuery accessible by $.

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

The div is meant to be concealed, however, it remains visible

Having some difficulty with error messages while creating a login form. Trying to hide the 2nd div unless the form has been submitted and the password is valid. The following html code is not functioning as expected: <div class="form-input"> & ...

Exploring the diversity of perspectives through Angular

Currently, I am in the process of integrating multiple views in Angular to address the footer issue on a website that I am constructing. I want to ensure that the information I have been studying and attempting to replicate is accurate. Here is what I have ...

Invoking a JavaScript class using a script tag

In my code, I have a class declaration in a script that is imported before the body tag: $(document).ready(function(){ var FamilyTree = function() { }; FamilyTree.prototype.displayMessage=function() { alert("test"); } }); Then, within the bo ...

Stopping the execution of a request handling function in Express/Node: tips and tricks

I am currently running an Express server that offers some computations as web services. The computation time can vary from less than 1 second to 10 seconds. I am curious if there is a method to halt the execution of a request-handling function (which is ...

Setting default values in Angular dropdown select using TypeScript

How can a default value be set in a Select element? I am attempting to create a time dropdown select with multiple options. Currently, the selectedTimeOption variable correctly identifies if an option is chosen from the dropdown, but it cannot detect a va ...

Adding JavaScript files to a project in Ionic2 with Angular2 integration

I'm looking to incorporate jQuery into my Ionic2 app, which requires loading several JavaScript files: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/j ...

I am having issues with this code as the submit button seems to be malfunctioning. Can you help me

Below is the code for sending data from leadgen.php to page-success.php, both of which are Wordpress pages stored in the same folder: jQuery.ajax({ url: "http://localhost/success-page", type: "POST", data: 'name=' +name+'&em ...

How to obliterate tinyMce completely?

I am currently working with version 3.4.b3 and have it displayed within a dialog where the content is generated dynamically. This means that the textarea tiny binds to is created each time. Therefore, when I open the dialog for the first time, tiny appear ...

Enhance the appearance of testNG's HTML report

Currently, I am conducting tests with testNG and Selenium, utilizing test data sourced from a CSV file. I have 17 parameters extracted from this CSV file that are functioning well. However, I am looking to modify the testNG HTML report for better identific ...

The child module invokes a function within the parent module and retrieves a result

Guardian XML <tr [onSumWeights]="sumWeights" > Algorithm sumWeights(): number { return // Calculate total value of all weights } Offspring @Input() onTotalWeights: () => number; canMakeChanges() { return this.onTota ...

After receiving the response, the Ajax success function does not run as expected

I have written the following code: $(".simpleCart_shelfItem button").click(function() { $(this).prop('disabled', true); $(this).addClass('disabled'); $(this).html("Adding &nbsp;&nbsp;<i cl ...

Tips for displaying nested components in React

I am currently facing a challenge involving rendering different database tables as HTML tables in React. The issue at hand is that each table has a different number of columns. In my component, I receive header data along with the full table data in JSON f ...

Guide to successfully implement a POST action using jquery/ajax Colorbox! Check out the demo here

I stumbled upon a colorbox tutorial and attempted to replicate it with a POST action, but unfortunately, it just continues to load. Check out this fiddle The button represents the problematic POST action, while the text link is the original example that ...

Having trouble getting the libphonenumber npm package up and running, encountering an error stating that fs.readFileSync is not functioning properly

I am currently working on incorporating the googlei18n libphonenumber library for validating phone numbers. I have installed the npm package using npm i libphonenumber. However, when I try to use it like this: var libphonenumber = require('libphonenu ...

Cannot change class until class is reapplied

Is there a way to remove the highlight class before reapplying it to other elements in order to reset the selected items? I tried using removeClass in the code below but it's not working. $("#toggleCustom").on("click", function () { var $this = ...

Where is the location of the response for Gravity Forms Ajax?

I have successfully integrated a gravity form into my WordPress site with no issues, as long as I use the standard response in the backend. My shortcode for pulling in the form is working fine: <?php echo do_shortcode('[gravityform id="2" ...

middleware for handling multiple domains in Next.js

Encountering the following error in the code snippet below: error - Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client. Additionally, I would like to execute redirectMiddleware only once for each user who visits this webs ...

Converting JavaScript code into PHP syntax

I'm curious about code organization. The original code in this snippet is functioning properly: <?php if (isset($_POST['submit'])){ ... ... $invalidField = 2; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD ...

Enhancing MySQL data retrieval with a custom jQuery timepicker integration

Two inputs need to be formatted for easy reading, but when a date is selected by the user, the output format should be compatible with MySQL. It seems that changing the view format independently from the output format is not possible. I am attempting to ac ...

Making a Chrome extension that allows for cross-domain jQuery.Ajax requests

Looking to develop a Google Chrome extension that displays a notification based on the result of an Ajax request. I have already created the function for generating notifications, all that's left is to make the Ajax request to fetch a .php file from ...