Show one line of text at a time with a pause in between each one

On my HTML page, I am looking to showcase text lines in succession with a delay. The unique condition is that when the second line appears, the color of the first line should change. Then, as the third line emerges, the color of the second line should also update.

Although I have integrated jquery.fadeInAmate.js for sequentially displaying the text lines with delays, there seems to be an issue with implementing the color change feature.

$(function() {
  setInterval(function() {
    $("#slideShow").show();
    $(".fadeInAmate").fadeInAmate({
      initialDelay: 250,
      fadeInSpeed: 2000,
      animationDelay: 5000
    });
  }, 1000);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://jforaker.github.io/jQuery-FadeInAmate/src/jquery.fadeInAmate.js"></script>
<div id="slideShow">
  <p class="fadeInAmate">This is my first line</p>
  <p class="fadeInAmate">Here goes my second line</p>
  <p class="fadeInAmate">Then comes third line</p>
  <p class="fadeInAmate">Following to that fourth line</p>
  <p class="fadeInAmate">And finally here goes my fifth line</p>
</div>

Looking forward to your help!

Answer №1

It seems like the current plugin being used does not provide any events (source), making it difficult to determine when an element starts fading in to change the color of previous elements. To address this, I recommend exploring a different library or implementing custom logic as shown below:

$("#slideShow .fadeInAmate").each(function(i) {
  $(this).delay(3000 * i).fadeIn(2000, function() {
    $(this).prev().addClass('foo');
  });
});
#slideShow p {
  display: none;
}

.foo {
  color: #C00;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://jforaker.github.io/jQuery-FadeInAmate/src/jquery.fadeInAmate.js"></script>
<div id="slideShow">
  <p class="fadeInAmate">This is my first line</p>
  <p class="fadeInAmate">Here goes my second line</p>
  <p class="fadeInAmate">Then comes third line</p>
  <p class="fadeInAmate">Following to that fourth line</p>
  <p class="fadeInAmate">And finally here goes my fifth line</p>
</div>

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 jQuery calendar malfunctions on desktop devices but functions properly on mobile devices

Experiencing an unusual issue with the jQuery calendar on my website. The code is within a block (widget) in the Flatsome theme on Wordpress, and I'm using the same block for both desktop and mobile versions of the header builder. Strangely, the calen ...

The .each method is failing to iterate over the next object

Currently, I have been working with JSON data retrieved from the web. After successfully receiving the data, I proceed to create a JavaScript object to work with it. However, there seems to be an issue with retrieving the values of fname and lname from th ...

Issues with jQuery functionality arise when attempting to delete items in Michael Hartl's tutorial, specifically in chapter 11

Currently, I am following the Rails tutorial by Michael Hartl, like many other newcomers to Rails. However, I have hit a roadblock in Chapter 11, specifically with an issue involving JQuery not working properly with the delete action. Whenever I click on a ...

When multiple input fields share the same class, only the first value is taken on POST

Currently, I have a form with the same input field repeated multiple times. While I initially used an ID for the input field, I had to switch to using a class since the field needed to be present in multiple instances on the form. Each time, the input is n ...

A common inquiry: how can one pinpoint a location within an irregular figure?

I have been studying Html5 Canvas for a few weeks now, and the challenge mentioned above has puzzled me for quite some time. An irregular shape could be a circle, rectangle, ellipse, polygon, or a path constructed by various lines and bezier curves... I ...

Searching for the closest jQuery value associated with a label input

As a beginner in JQuery, I am looking to locate an inputted value within multiple labels by using a Find button. Below is the HTML snippet. Check out the screenshot here. The JQuery code I've attempted doesn't seem to give me the desired output, ...

What is the method for setting up vertical tabs?

Is it possible for someone to provide guidance on how to create vertical tabs for the HTML content below? When a tab, such as tab1 in the left column, is clicked, only the content of tab1 should be displayed in the middle column. The same applies for tab2 ...

Implementing microdata without visibly displaying tagged entities on the webpage

I have a query regarding the implementation of Microdata on my webpage where tagged entities are not being displayed. For instance, I want to talk about two individuals in a paragraph without their names appearing on the webpage. Is there a method to only ...

json Shawn's success message

I am currently working on a project where I am trying to confirm the successful sending of an email using JSON, followed by catching the event with Ajax and displaying a success message on the screen. The issue I am facing is that the email is not being se ...

Employ PHP to add HTML elements to an image

Currently, I am exploring ways to add captions to the product thumbnails on my WordPress ecommerce website. My plan is to extract the "alt" tag from each image and wrap it in tags that will allow me to apply CSS styles to the caption. My search led me to ...

What is the best way to create a border of white space around the background color of a table cell using CSS?

Is there a way to create a white space around the background color of a table cell using CSS? My current code has the background color extend all the way to the edge, and padding only affects the content, not the background color. #main-monitor { widt ...

Calculator built with HTML, CSS, and JavaScript

Hi there, I'm experiencing some issues with my calculator. The buttons seem to be working fine and lining up correctly, but for some reason, nothing is showing up on the monitor or getting calculated when I press the buttons. Here's the code that ...

Once a value is selected from the datalist input autocomplete, it loses focus

My issue involves using an input with a dynamic datalist for auto completion. To achieve this, I've implemented the following approach: A key function in my process is as follows: $(function () { $("#to").on("input", function (e) { ...

Binding event listeners to dynamically created elements poses a challenge

I am facing difficulty in adding an event listener to dynamically created elements. The issue lies in my code where I am unable to detect the insertion of <p> element resulting in the lack of console message Bar Inserted. Could you point out if there ...

Choose all div elements except for those contained within a certain div

Having trouble with an IE7 z-index fixer that's affecting specific elements. I'm attempting to select all divs, excluding those nested within a particular div. Below is the jQuery code I'm using, but it's not functioning correctly: & ...

Converting an Image to Memory Stream in JavaScript

Incorporating the jquery.qrcode library, I am able to create a QR code image that is output in the following format. <img src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAA ...

The issue of MUI components overlapping arises during window resizing

I am currently working on a chat component that includes both the chat display and message input fields. function Chat() { const chatBoxStyles = { bgcolor: "red", height: "70vh", mt: "1rem" }; const messageIn ...

Likelihood of triggering a function based on percentage

Hey everyone, I'm looking to add some randomness to the buttons on my website. I have a Button that could activate function one, function two or function three. However, I want to make it so there is a 60% chance that function one gets called from the ...

Hide the row count in a JQuery datatable

I recently implemented a jQuery datatable plugin in my HTML table using the following code: (#client-table).dataTable() After the implementation, it now shows "Showing 1 to 3 of 3 entries" below the table. I'm wondering if there is a way to hide or ...

Show the file name in the email signature instead of displaying the image

I'm facing a unique challenge with images in my HTML email signature. Sometimes the images are replaced by their file names on certain email hosts. Interestingly, I can't replicate this error now as the images are displaying correctly again! He ...