Implementing a delay between two div elements using jQuery

I have two Divs with the class "sliced", each containing three images with the class "tile". When I animate using jQuery, I am unable to add a delay between the "sliced" classes. However, I have successfully added a delay between the "tile" classes.

index.html

<!DOCTYPE html> 
     <html>
        <head>
            <title>Testing Scripts</title>
            <link rel="stylesheet" type="text/css" href="style.css">
        </head>
        <body>




        <div id="slider-wrap">
            <div class="sliced">

                    <div class="tile"><img src="http://imageshack.us/a/img545/9813/58zj.jpg" alt"1"></div>
                    <div class="tile tile1"><img src="http://imageshack.us/a/img818/5776/8ik6.jpg" alt"1"></div>
                    <div class="tile tile2"><img src="http://imageshack.us/a/img18/6017/rue6.jpg" alt"1"></div>
            </div>  
            <div class="sliced " >

                    <div class="tile"><img src="http://imageshack.us/a/img163/6131/ld3f.jpg" alt"1"></div>
                    <div class="tile tile1"><img src="http://imageshack.us/a/img838/4102/h0nv.jpg" alt"1"></div>
                    <div class="tile tile2"><img src="http://imageshack.us/a/img833/6500/dp5e.jpg" alt"1"></div>
            </div>  
         </div>   


         </div>
        <script src="jQuery.js"></script>
        <script src="jquery.easing.1.3.js"></script>
        <script src="script.js"></script>
        <script>$('.sliced').slider();</script><!--Calling plugin with   -->
        </body> 
     </html>

CSS

body {
    width: 960px;
    margin: 100px auto;
    font-family: helvetica;
    font-size: 20px;
 }

#animate {
    width: 100px;
    height: 30px;
    margin-bottom: 10px;
    font-size: 16px;
}
.sliced {
    position: relative;
    margin: 5px 5px;
    width: 900px;
    height: 200px;
    border: 2px solid black;
    }
.box {
    width: 600px;
    border: 2px solid rgba(0,0,0,.05);
    padding: 10px 10px;
}

img {
    width: 270px;
    height: 150px;

}
.tile {
    position: absolute;
    float: left;
    margin: 25px 15px;
}
.tile1 {

    left: 280px;

}
.tile2 {

    left: 560px;

}

JScript:-

function Slider(element){
    var $element = $(element), //Jquery Object of .sliced class
        $tiles = $element.find('.tile');  //$tiles contains all .tile class as jquery Object
        $.each($tiles,function(index,value){ 
               setTimeout(function(){
                $(value).fadeOut(1000);
                },1000*index);

        });

} 

$.fn.slider = function(){   
       //This stores all .sliced class as Jquery object                                      
    return this.each(function(){  //Iterating over each class provided 
        var slider = new Slider(this);  //Slider is constructor function
        //console.log(slider);
    });
}

Answer №1

At long last, after numerous attempts and experiments, I finally managed to figure it out on my own

JavaScript:-

function Slideshow(element, index){
    var $element = $(element), //Jquery Object of .sliced class
        $tiles = $element.find('.tile'),//$tiles contains all .tile class as jquery Object
        delay = 5000;  //Delay between two divs
        
        setTimeout(function(){
             $.each($tiles,function(index, value){ 
               setTimeout(function(){
                $(value).fadeOut(1000);
                },1000*index);
          });
        },delay*index);
} 

$.fn.slideshow = function(){   
       //This stores all .sliced class as Jquery object                                      
    return this.each(function(index){  //Iterating over each class provided 
        var slideshow = new Slideshow(this,index);  //Slideshow is constructor function
        //console.log(slideshow);
    });
}

Answer №2

How about considering this suggestion:

$( "div" ).click(function() {
  $( this ).addClass( "big-blue", 1000, "easeOutBounce" );
});

Do you think this could be beneficial?

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 JavaScript code will automatically execute loops

Let me illustrate my point with two functions. Function 1 This function triggers a transition when you hover over the square. If you move your mouse off the element and then back on while the transition is still in progress, it will wait until the end of ...

Modifying the ptTimeSelect functionality in conjunction with the validationEngine plugin

Currently, I am facing a challenge with my input field that is programmed to display the ptTimeSelect time picker while also requiring the use of validationEngine for field required validation. The issue at hand is as follows: When the input field is in ...

When I engage with the input field, it ceases to be in focus

Here is the code I've been working on: https://github.com/Michael-Liendo/url-shortener/blob/main/src/pages/index.js If you want to see the issue for yourself, check it out at: ...

What is the best way to alter the order of the .map function in JavaScript to display in ascending or descending order?

I currently have 25 songs in my Spotify playlist, with the possibility of more being added in the future. The songs are numbered from 1 to 25. However, the map() function I use only displays the top 10 songs (1 to 10). When a new song is added, it is assig ...

Find the location in a node.js script where a promise was rejected

Recently, I encountered a code snippet from an npm package that has been causing me some trouble. The issue is that I'm having difficulty in pinpointing where the rejected promise is being created or rejected within node.js. const someHiddenEvil = fu ...

Leveraging $http or $timeout in conjunction with $stateProvider in AngularJS

I am seeking guidance on loading a template for a specific state in Angular using $http after coming across this question on Stack Overflow: Is it possible to load a template via AJAX request for UI-Router in Angular? The documentation for ui.router demon ...

Utilizing the `filterBy` function with a custom select list that changes dynamically

I'm currently in the process of constructing a form with an extensive selection of drop-down items utilizing vue.js. My approach involves implementing the dynamic select list as detailed in this documentation: However, I am interested in providing us ...

Comparison of element state prior to and post editing (with contentEditable)

Exploring how elements within a div can be monitored for changes made by the user (thanks to contentEditable), I created a sample page with the following setup: before_html = $("#example_div").children(); $("#differences_button").on("click", ...

Altering the input type of a cloned element in Internet Explorer results in the loss of the value

When I have checkbox inputs displayed in a modal with preset value attributes, upon clicking "OK", I clone them and change their input types to hidden, then append them to a div in the document body. However, when trying to retrieve their values using jQue ...

Number Stepper Reverse

Could the HTML5 number stepper be reversed so that pushing down increases the number and vice versa? In Response to any 'Why?' inquiries: Consider batting order in sports like cricket or baseball. As you move down the order, your batting positio ...

When floating a heading 4 (h4) and two divs to the left, and a single div to the right,

When floating a h4 and 2 divs to the left, and another div to the right, how can I place a block inside the remaining space that perfectly fills it? The background color of this space should not spread outside. [h4][div][div][remaining space][div] Thank ...

Set a consistent pixel measurement for all images

I am working on a project where I have an image of a card that needs to be repeated 30 times. Each time the card is repeated, I want it to overlap with the previous card in a specific position, resembling a deck of cards. The issue I am facing is that whe ...

Assign a unique HTML attribute to a child element within a Material-UI component

Currently, I am trying to include the custom HTML5 attribute "data-metrics" in the span element within the ListItemText Material UI component. However, I am facing some difficulty achieving this as per the specifications outlined in the Component API Docum ...

Node Js is a lightweight server that allows for easy querying of URLs

I've been exploring various examples but I'm still struggling to understand how it all functions. My goal is quite simple, or so I thought. I was hoping someone could assist me? The task at hand is to establish a server for clients to connect t ...

An array is not just a mere collection of elements

I have an object that resembles an array var items = [ { started_time: 2017-05-04T12:46:39.439Z, word: 'bottle', questionId: '161013bd-00cc-4ad1-8f98-1a8384e202c8' }, { started_time: 2017-05-04T12:47:26.130Z, word: &apo ...

aligning adaptable grid on the screen

Is anybody able to assist me in vertically centering the responsive matrix below so that it is equidistant from the left and right edges of the screen (parent element has a width of 100%)? Any help would be greatly appreciated. Here is my code: <!DOC ...

Is there a way to give only the left corners of a button a rounded look?

Here is the visual representation of the button: https://i.stack.imgur.com/Bjlkp.png ...

Creating PDF files with PDFkit in Node.js while rendering HTML data

I am looking for a way to generate a PDF file using the 'PDFkit' library. The data is being retrieved from a MySQL database, and some of the content includes HTML tags. However, when I try to render the HTML data to PDF using the 'html-to-te ...

Exploring the Wonderful World of Styled Components

I have a query regarding styled components and how they interact when one is referenced within another. While I've looked at the official documentation with the Link example, I'm still unclear on the exact behavior when one styled component refe ...

Inject fresh variable values into the serialization process

Within my login form, I have fields for Username and Password. Upon clicking the login button, a Javascript function is triggered to make an ajax request to the login controller. To serialize the form data, I used the code snippet below: var parameters = ...