JavaScript - Delayed Text Appearance with Smooth Start

I want to create a landing page where the text appears with a slight delay - first, the first line should be displayed followed by the second line. Both lines should have an easing effect as they appear. Below is a screenshot of the section:

https://i.sstatic.net/kDGDd.png

The word "Welcome" should show up first, followed by "To the Bullshit Collection". I attempted to follow the advice provided in this treehouse article. However, when implementing Lauren's method, the word "Welcome" doesn't display at all.

https://jsfiddle.net/fjvLwmrq/

Using Rob's approach, the code `}//]]>` immediately appears (without any delay) instead of "Welcome".

https://jsfiddle.net/a49rxo19/

Here is the HTML code:

<div class="parallax-window" data-parallax="scroll" data-image-src="/wp-content/themes/TheBullshitCollection/Images/white-background.jpg">
<div class="welcome-div">
    <h3 class="welcome">Welcome</h3>
</div>

<div class="to-the-bullshit-collection-div">
    <h3 class="to-the-bullshit-collection">To the Bullshit Collection</h3>
</div>

<section id="section5" class="demo">
    <a href="#section5"><span></span>Scroll</a>
</section>
</div>

CSS styles:

.parallax-window {
height: 100vh;
}

.welcome {
text-align:center;
font-family: Beautiful ES;
font-size: 185px;
font-weight: lighter;
}

.to-the-bullshit-collection {
text-align:center;
font-family: Beautiful ES;
font-size: 185px;
font-weight: lighter; 
}

#section5 {
text-align:center;
}

#section5 a {
padding-top: 70px;
font-family: PT Sans Narrow;
text-transform: Uppercase;
text-decoration: none;
font-weight: bold;
color: #000000;
}

JavaScript snippet:

// JavaScript functions
(function ($, root, undefined) {
$(function () { 
    'use strict';       
    // DOM ready, take it away      
    }); 
})(jQuery, this);

// Landing page text delay function
function showWelcomeDiv() { 
    document.getElementById("welcome-div").style.display = "inline"; 
}
// Call the above function after 1 second
setTimeout("showBuyNow()", 1000);

Any insights on what might be causing the issue? Thank you!

Answer №1

Do you find this approach to be more straightforward?

/*WindowOnload Fade-In*/

@keyframes chainReaction {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}


/*div p {
  animation: chainReaction 2s;
  opacity: 0;
  animation-fill-mode: forwards;
}*/


.parallax-window .welcome-page-div {
  animation: chainReaction 3s;
  opacity: 0;
  animation-fill-mode: forwards;
  text-align: center;
  font-family: Beautiful ES;
  font-size: 30px;
  font-weight: lighter;
}

.parallax-window .welcome-page-div:nth-child(1) {
  animation-delay: .3s;
}

.parallax-window .welcome-page-div:nth-child(2) {
  animation-delay: 1s;
}


/*WindowOnload Fade-In*/
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parallax-window" data-parallax="scroll" data-image-src="/wp-content/themes/TheBullshitCollection/Images/white-background.jpg">
  <div class="welcome-page-div">
    <h3>Welcome</h3>
  </div>

  <div class="welcome-page-div">
    <h3>To the Bullshit Collection</h3>
  </div>

  <section id="section5" class="demo">
    <a href="#section5"><span></span>Scroll</a>
  </section>
</div>

Answer №2

If you're looking to add a delay effect to your text, check out this jQuery plugin. See the demonstration here.

After importing jQuery, simply include the script:

<script src="https://cdn.jsdelivr.net/gh/jrquick17/jquery-delay-text/delay-text.js"></script>

Then, use a jQuery selector to target the elements with the desired text:

$('h3').delayText({ sequential: true });

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

How can Request.UrlReferrer be configured using client-side JavaScript? If it can be done, what is the process?

In my application, I heavily rely on Request.UrlReferrer to handle link clicks and maintain a page history for users. Due to new requirements, I now need to navigate to a specific location using <input type="button" /> instead of <a href="mypage. ...

Using javascript to generate fresh dictionaries

Struggling to translate a C# "function" into JavaScript - any advice or tips? Here is the C# snippet: var parameters = new Dictionary<string,string> { { "link", "http://mysite.com" }, { "name", "This is an test" } }; I believe I need to ut ...

Struggling with aligning mat-icon in the center using HTML and CSS?

My issue is that the mat-icon in my generated columns is not center aligned. What could be causing this? When using ngFor to generate my datatable columns dynamically, none of them align correctly. The mat-icon inside my DIV defaults to left alignment. ...

Adding multiple files and additional inputs to formData for PHP processing

I am dealing with a situation where I have multiple forms that are generated dynamically. In addition to handling these forms, I also need to construct the formData for multiple files along with some extra hidden inputs. Here is the approach I have taken ...

Guide on how to retrieve a clicked element

When I click on the <ul> inside this div, I want to retrieve the id="nm". <div id="suggestionTags"> <ul> <li class="nm">Commonwealth</li> <span class="cty"> x GB</span> <li class="hse">C ...

The onClick event's detail property is persisting even after the React component has been replaced

In the onClick event, the value of event.detail indicates the number of clicks, with a double-click having event.detail = 2. It seems that when the React component being clicked is replaced, the event.detail value does not reset. This could be due to Reac ...

What is the indicator that signals a change in the value of a React ref.current?

Typically, when using props, we would write componentDidUpdate(oldProps) { if (oldProps.foo !== this.props.foo) { console.log('foo prop changed') } } to identify any changes in props. However, if we utilize React.createRef(), how can w ...

What could be causing my Bootstrap (3) grid to not display responsively?

It seems like there may be a simple oversight in my code, as I'm unable to make my Bootstrap grid responsive. I have successfully passed item data through Node and am able to display a grid of item thumbnails with captions in rows of 4. However, when ...

Using Jquery Mobile to make an AJAX POST request with XML

Is it possible to use this code for XML parsing? I have successfully parsed using JSON, but there is no response from the web service. This is the status of the webservice: http/1.1 405 method not allowed 113ms $j.ajax({ type: "GET", async: false, ...

Issue with CSV download box not showing up on Rails version 2.3.11

I've encountered an issue while trying to export a csv file with some data. I am using ajax call to select rows from the view table (jqGrid) and export them in a csv format. However, after a successful ajax call, the filtered data is displaying as an ...

The design template is failing to be implemented on my personal server utilizing node.js

I've encountered an issue while developing the signup page on my local server using Bootstrap 4. The CSS is not getting applied properly when I run it locally, although it displays correctly in the browser. Can someone explain why this is happening? ...

Transforming a circular data structure into JSON format within Firebase

https://i.sstatic.net/BhQtp.png The data returned from firebase is causing an issue when I try to stringify it: JSON.stringify(data) // where data represents the returned object This results in the error: TypeError: Converting circular structure to JSON ...

Steps for successfully passing an object in a dynamically generated function invocation

In my jQuery script, I have a click event bound to thumbnail images with the class "thumbnail": $(".thumbnail").click(function(){ var obj = new Object(); obj.el = "imageEdit"; obj.id = $(this).attr("id").replace("img_",""); openDialogue(obj); }); ...

Update the numerical data within a td element using jQuery

Is there a way to use jquery to increase numerical values in a <td> element? I've attempted the following method without success. My goal is to update the value of the td cell by clicking a button with the ID "#increaseNum". Here is the HTML st ...

Transferring information between two tables in a MongoDb database

My current database in mongo is named "sell" and it contains two tables: "Car" and "Order". In the "Car" table, there is an attribute called "price". When I run the following command in the mongo shell: db.Order.aggregate([ { $lookup: { from: ...

PHP form headaches: issues with submitting and posting

I'm having trouble with the submit button in my PHP code. Here's what I have so far (it's for a website where users can rate things): <form method="POST> <input type="radio" name="person" value="1" /> <input type="radio" name ...

Struggling with Bootstrap 4 - need help with navbar and flexbox alignment issues

My goal is to recreate a navigation bar similar to this design: navbar I initially attempted to use the grid system for my navbar, but it didn't work out as expected. After some research, I found that using the grid system for navbars is not recomme ...

JQuery for Seamless Zoom Functionality

I am working with some divs that have images as backgrounds, and I have added a zooming effect on hover. However, the zoom effect is not smooth. Is there a way to modify the script to make the zoom effect smoother? Here is an example of my HTML structure: ...

What is the best way to store a downloaded video from the server?

I am currently in the process of downloading a video from a server using JavaScript XHR (specifically Angular $http GET with response type 'blob'). My question is, how can I save this downloaded video to a Chrome application's local storage ...

Storing Firestore Timestamp as a Map in the database

Snippet Below const start = new Date(this.date + 'T' + this.time); console.log(start); // Thu Sep 12 2019 04:00:00 GMT+0200 const tournament:Tournament = { start: firebase.firestore.Timestamp.fromDate(start) } When passing the tournament ...