Employing JavaScript for fading divs in and out sequentially

Hey there! I'm currently struggling with implementing transitions for my tool tips. Any assistance would be greatly appreciated!

I am looking to have my "fader" divs fade in and out on click of a button, with each transition lasting 5 seconds. It's like a quick tutorial for my new UI.

Below is the code I've been working on:

JS


function fadeLoop() {

var counter = 0,
    divs = $('.fader').hide(),
    dur = 500;

function showDiv() {
    divs.fadeOut(dur)
        .filter(function(index) {
            return index == counter % divs.length;
        })
        .delay(dur)
        .fadeIn(dur);
    counter++;
};
showDiv();
return setInterval(function() {
    showDiv();
}, 5 * 1000);    
};

$(function() {
var interval;

$("#start").click(function() {
    if (interval == undefined){
        interval = fadeLoop();
        $(this).val("Stop");
    }
    else{
        clearInterval(interval);
        $(this).val("Start");
        interval = undefined;
    }
});
});

HTML

<div class="fader">
<div id="tutorial1" class="tutorial createquestion1">
    <div class="arrow-w" style="font-size:1em;" >
    </div>
    &nbsp;Start by creating a title and selecting a folder for your question to be stored in.
</div>
</div>
<div class="fader">
<div id="tutorial2" class="tutorial createquestion2">
    <div class="arrow-w" style="font-size:1em;" >
    </div>
    &nbsp;Categories are key to your reporting effectiveness, be sure to include categories that relate to this question.
</div>
</div>
... (additional HTML fader elements)
<input type="button" value="Start" name="Start" />

CSS

.tutorial {
display: table;
border: 4px solid #8C3087;
...
.createquestion6 {
top:140px;
left:100px;
text-align:right !important;
}

Answer №1

To begin, give your button an identification by including an ID for the jQuery click handler to recognize

<button id="start" type="button" value="Start"></button>

Answer №2

For your html to function properly, it must align with the javascript.

If you need a working example, check out this version: jsFiddle

HTML

<div class="fader tutorial" id="createquestion1">
    <div class="arrow-w" style="font-size:1em;"></div>
    &nbsp;Begin by creating a title and choosing a folder to store your question.
</div>

<div class="fader tutorial" id="createquestion2">
    <div class="arrow-w" style="font-size:1em;"></div>
    &nbsp;Including relevant categories is crucial for effective reporting.
</div>

<div class="fader tutorial" id="createquestion3">
    <div class="arrow-w" style="font-size:1em;"></div>
    &nbsp;Choose options or upload an attachment (file, video, audio).
</div>

<div class="fader tutorial" id="createquestion4">
    <div class="arrow-w" style="font-size:1em;"></div>
   Update your question preferences in your account area for easier question creation.&nbsp
</div>

<div class="fader tutorial" id="createquestion5">
    <div class="arrow-w" style="font-size:1em;"></div>
    &nbsp;Use rationale for student feedback and internal comments for tracking changes and updates.
</div>

<div class="fader tutorial" id="createquestion6">
    <div class="arrow-w" style="font-size:1em;"></div>
   Write your questions and answers to get started.&nbsp;
</div>

<input type="button" value="Start" id="start"/>

CSS

#start{
    right:1em;
    top:1em;
    padding:1em;
}

.tutorial {
    display: table;
    border: 4px solid #8C3087;
    -webkit-border-radius: 15px;
    -moz-border-radius: 15px;
    border-radius: 15px;
    -moz-box-shadow:1px 1px 3px 2px #ccc;
    -webkit-box-shadow: 1px 1px 3px 2px #ccc;
    box-shadow: 1px 1px 3px 2px #ccc;
    position:absolute;
    padding: 11px;
    font-family: 'Archivo Narrow', sans-serif;
    background-color:#ECA100;
    width:200;
    z-index:2000;
    font-size:12pt; 
    color:#000;
    vertical-align:top;
}

.arrow-n,
.arrow-e,
.arrow-s,
.arrow-w {
    border-style: dashed;
    border-color: transparent;
    border-width: 0.53em;
    display: -moz-inline-box;
    display: inline-block;
    font-size: 100px;
    height: 0;
    line-height: 0;
    position: relative;
    width: 0;
    text-align:left;
}

.arrow-n {
    border-bottom-width: 1em;
    border-bottom-style: solid;
    border-bottom-color: #8C3087;
    bottom: 0.25em;
}

.arrow-e {
    border-left-width: 1em;
    border-left-style: solid;
    border-left-color: #8C3087;
    left: 0.25em;
}

.arrow-s {
    border-top-width: 1em;
    border-top-style: solid;
    border-top-color: #8C3087;
    top: 0.25em;
}

.arrow-w {
    border-right-width: 1em;
    border-right-style: solid;
    border-right-color: #8C3087;
    right: 0.25em;
}

#createquestion1 {
    top:140px;
    left:320px;
    text-align:left;
}
#createquestion2 {
    top:240px;
    left:320px;
    text-align:left;
}
#createquestion3 {
    top:340px;
    left:320px;
    text-align:left;
}
#createquestion4 {
    top:60px;
    right:10px;
    text-align:right !important; 
}
#createquestion5 {
    top:520px;
    left:320px;
    text-align:left;
}
...

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

Implement the insertion of JSON items in real-time by leveraging the power of Angular JS and

I'm facing a challenge trying to insert JSON items into a dynamic list: The structure of my JSON file is as follows: [ { "id":"34", "City":"New York", "Country":"USA" }, { "id":"22", "City":"Las vegas", "Country":"USA" }, { "id":"44", "City":"Paris" ...

Filtering a Two-Dimensional Array Using JavaScript

I am working with a basic 2D array that contains x, y coordinates as shown below: var c = [ [1,10], [2,11], [3,12], [4,13], [5,15] ]; I want to know how I can extract pairs from the array that meet specific conditi ...

Tips for updating the content of a div with fresh data using a slideshow effect in jQuery

Imagine you have a div called A and an array filled with text data. When t=0, div A will display $data[0]. Then, after every n seconds, I want the div to show the next piece of data in the array. I am interested in creating a transition effect similar to ...

Mixing together an array of colors, experimenting with adding a touch of transparency

Here is my first question, diving right in. I recently created a canvas in HTML and followed a tutorial to generate random floating circles that interact with the mouse position......if you want to check it out, click here. The issue I'm facing now ...

Disappear text gradually while scrolling horizontally

There is a need to create a special block that displays fading text on horizontal scroll. However, the problem is that the block is situated on a non-uniform background, making the usual solution of adding a linear gradient on the sides unsuitable. Click ...

Mastering the art of bi-directional data binding with nested arrays in Angular

Imagine you have a to-do list with various tasks, each containing multiple subtasks. You want the ability to change the subtask data, but why is Angular not properly two-way binding the data for the subtasks? HTML <div *ngFor="let task of tasks"> ...

Looking to implement a scroll bar in your PhoneGap mobile app for Android?

Encountering an issue with my Android PhoneGap mobile website application. I have implemented a scroll bar in the application which works perfectly on PC. However, when testing on an Android device (mobile phone), the scroll bar does not enable. ...

When switching to compatibility view in IE 9, ASP.NET MVC 5 with Angular may cause the browser to crash

Upon deploying my site with MVC 5, Api 2 integrated with Angular and JQuery onto an intranet server, I encountered a strange issue. Due to internal policy restrictions, all sites on the intranet must operate under compatibility view. This caused a problem ...

Having issues with the tailwindcss transformation not functioning properly, but the problem seems to resolve when directly incorporating it into the

Lately, I decided to start utilizing tailwindcss and I have noticed that certain properties do not seem to function at all. However, when I incorporate them into my CSS directly, they work perfectly fine. Allow me to provide an example. const Step = styled ...

Converting a single 10GB zip file into five separate 2GB files with the help of NodeJS

var fs = require('fs'); var archiver = require('archiver'); var output = fs.createWriteStream('./test.zip'); var archive = archiver('zip', { gzip: true, zlib: { level: 9 } // Sets the compression level. }); ...

Tips for adding a string variable to a JQuery HTML element attribute

Hi there, I've been working on a JQuery code to append data to a div element and it's been successful so far. Here is the code: $('#conversation').append('<div id="receiver"><p><b>' + username + ':< ...

What is the best way to extend a class in NestJS from another class?

I've encountered an issue while attempting to extend a class service from another class service in NestJS and utilize DI to load it in a third service. The error message I'm receiving from Nest is: Error: Nest can't resolve dependencies of ...

Disable sorting options in the Datatable ColumnFilterWidget

I'm currently working with datatables ColumnFilterWidget and I'd like to prevent the widget from sorting the values displayed in the select box. Despite trying the "bSort": false option of the ColumnFilterWidget, it doesn't seem to have any ...

Sending properties within components using #createElement in React-Router is a convenient way to pass data locally

Have you ever wondered where the parameters Component and props are coming from in the React-Router documentation? // Here is the default behavior function createElement(Component, props) { // ensure all props are passed in! return <Component {... ...

Grab a parameter from the URL and insert it into an element before smoothly scrolling down to that

On a button, I have a URL that looks like this: www.mywebsite.com/infopage?scrollTo=section-header&#tab3 After clicking the button, it takes me to the URL above and opens up the tab labeled tab3, just as expected. However, I would like it to direct m ...

Eliminating the default inline style automatically

My goal is to hide a table row until a radio button is clicked. I attempted using display:none;, but it did not work. Upon inspecting the code in my developer tools, I noticed that the specific table row has a style attribute style="display: table-row; whi ...

JavaScript has encountered a syntax error

When working on an animation in javascript, I encountered a problem that I can't seem to identify. I am attempting to make the pan function work with the "mover" function, but it seems like either I am not using the properties correctly within the "tr ...

Is it possible to link an HTML select element to a changing array in JavaScript?

Let's say I have an empty HTML select element. <select id="options"> </select> Can I link a JavaScript array to this select so that when the array is modified, the select options update accordingly? Alternatively, do I need to resort to ...

Encountered an unhandled runtime error: TypeError - the function destroy is not recognized

While working with Next.js and attempting to create a component, I encountered an Unhandled Runtime Error stating "TypeError: destroy is not a function" when using useEffect. "use client" import { useEffect, useState} from "react"; exp ...

Change elements in real-time

I have a requirement to adjust elements with the class .super-elem by adding an attribute adjusted="true". Initially, I can easily achieve this within the document's ready event : $(".super-elem").attr("adjusted", "true"); However, I may add more . ...