December 28, 2024
1 min read
Sequential Fading Text October 8, 2023

Introducing Sequential Fading jQuery Text Animation – where words come alive on your website. With smooth fades and elegant transitions, your text captures attention effortlessly. Elevate your web design, engage visitors, and make a lasting impact. Explore the magic of subtle animation today!

Sequential Fading Text October 8, 2023

Here is the HTML

<div class="intro_text">
    <h1>
      <span>Here jQuery Text Animation 1</span>
      <span>Here jQuery Text Animation 2</span>
      <span>Here jQuery Text Animation 3</span>
    </h1>
  </div>

jQuery code for functionality

Script.js
(function ($) {
  "use strict";

  jQuery(document).ready(function ($) {
    //text animation code.mukto.info
    const spans = document.querySelectorAll('.intro_text h1 span');
    let index = 0;

    function fadeInNextSpan() {
      spans[index].style.display = 'inline';
      spans[index].style.opacity = 0;
      const fadeInEffect = setInterval(function () {
        if (spans[index].style.opacity < 1) {
          spans[index].style.opacity = parseFloat(spans[index].style.opacity) + 0.02;
        } else {
          clearInterval(fadeInEffect);
          setTimeout(fadeOutCurrentSpan, 5000); // Visible time of 5 seconds
        }
      }, 10); // Fading in over 1 second

    }

    function fadeOutCurrentSpan() {
      const fadeOutEffect = setInterval(function () {
        if (spans[index].style.opacity > 0) {
          spans[index].style.opacity = parseFloat(spans[index].style.opacity) - 0.02;
        } else {
          clearInterval(fadeOutEffect);
          spans[index].style.display = 'none';
          index = (index + 1) % spans.length;
          setTimeout(fadeInNextSpan, 10); // Gap between texts showing (1 seconds)
        }
      }, 10);
    }

    fadeInNextSpan(); // Start the animation loop

  });

}(jQuery));

We need a little CSS to hide all other text except 1st one

style.css
.intro_text h1 span{
  display: none;
}
.intro_text h1 span:first-child{
  display: block;
}

Use your creativity to customize your own way. Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

Jquery Replace specific text in all element

Scenario Imagine you have a set of elements with the class specific_class, and they all contain the phrase “old text.” You want to replace this phrase with “New text” programmatically. The Solution Here’s a simple jQuery script to achieve this: How It Works Things to Keep in Mind Extending the Script jQuery provides a quick […]

Allow Only Business Email Addresses in the Email Field of Elementor Forms

Find out how to restrict email fields in Elementor forms to business emails only. Improve form data quality by blocking free email domains like Gmail and Yahoo.

Implementing WooCommerce Shop Page Quantity Input and Plus (+) Minus (-) Button with simple Code

Enhance the user experience on your WooCommerce website by adding quantity plus minus buttons and a quantity option on the shop page.

wp-config development code

WordPress post revisions, debug, load-scripts.php problem fix code

Web Development Project in mind?

if you looking for a web developer for paid contribution to your project I am available for work.

Mukto
Mukto

Click the button below to chat with me.