What are the best strategies to prevent text from appearing jumpy while fading in word by word?

I'm struggling to create a smooth fade-in effect word by word without causing the first word to suddenly jump to the left when the second word appears.

To better explain my issue, I've provided a jsfiddle link: http://jsfiddle.net/6czap/504/

If anyone could advise me on how to resolve this problem, I would greatly appreciate it. Thanks.

<div class="headline">
Digital Journalist
</div>


var $title = $(".headline:first"), text = $.trim($title.text()),
words = text.split(" "), html = "";

for (var i = 0; i < words.length; i++) {
html += "<span>" + words[i] + ((i+1) === words.length ? "" : " ") + "       </span>";
};
$title.html(html).children().hide().each(function(i){
  $(this).delay(i*900).fadeIn(700);
});
$title.find("span").promise().done(function(){
    $el.text(function(i, text){
       return $.trim(text);
    });            
});

Answer №1

The reason behind this behavior is

body {
    text-align: centre;
}

Each time a new word gets added, the 'centre' position gets recalculated.

It's worth mentioning that you assigned a class to the <a> element but never utilized it.

You might want to consider using a margin instead of text-align:

.subtitle {
    margin-left: 40%;
}

You can test this out at http://jsfiddle.net/kdgm6rcm/1/

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

Tips for successfully submitting multiple forms to a controller

I'm working on a project that has multiple forms on the same page, and I need to pass them all to a controller in one go. How can I accomplish this? <script> function onSaveButtonClicked() { var form = $("#SaveForm").serialize(); var fo ...

"Exploring the best way to loop through multiple JSON data in a jQuery response

https://i.stack.imgur.com/O0F6g.pngMy JSON response contains multiple data points presented as follows. WellNames […] 0 {…} id 56 well_name AL HALL api 34005205550000 1 {…} id 498 well_name BONTRAGER api 34005233850000 2 {…} id 499 ...

What are the various ways to display time zone in a different format?

I need to display the timezone in a unique manner. I have captured the user's timezone in a variable called timeZone, which currently returns the value as Asia/Calcutta. console.log(timeZone) // "Asia/Calcutta" Is there a way to showcase the timezon ...

Rails javascript not triggering even after the page is loaded with `page:load`

My experience with using Stripe in Rails has been smooth, except for some issues with Ajax calls not working properly after page refresh. I suspect this might be related to Turbolinks as the 'ready page:load' event doesn't behave as expected ...

Tips for uncovering a concealed div within an iframe?

It's as if there's a mystery surrounding how to reach this elusive div... div#someId iframe html>head>body div.wrapper div.footer Naturally, my strategy: #someId iframe body .footer is proving to be ineffective. ...

A webpage styled with w3.css featuring text without any underline

I am currently using w3.css but I'm facing an issue where some of my hyperlinks have underlines while others do not. My goal is to remove all underlines from the hyperlinks in the content below: <ul class="w3-ul w3-white"> <a class="" href=" ...

Has the querystring hack become outdated?

For a long time, I have been adding a query string to my CSS link whenever I made changes that needed to be reflected on client machines: <link href="/Resources/styles/styles.css?v=1" rel="stylesheet" /> Lately, I've noticed that Chrome seems ...

What is the best way to prevent a strikethrough from appearing on the delete button in my JavaScript TO-Do application?

I'm working on coding a to-do app using JavaScript, HTML, and CSS. The issue I'm facing is that when I add the text-decoration: line-through property to the list items, it also affects the X icon used for deleting tasks. I suspect this problem ar ...

The button remains active in Internet Explorer 10 and cannot be disabled

The button has been specified as <input type="button" id="disable" disabled="disabled" value="Upload" /> However, the appearance of the button does not show it as disabled in Chrome, Firefox, and Safari. Additionally, in Internet Explorer, the bu ...

Is there a way in Javascript or JQuery to determine if a function is currently executing, or is there a way to tap into a return event?

Let me paint a picture of a common scenario: there's a form with numerous inputs (around 60-70). Each input must undergo validation, and if it is invalid, the form returns false. To prevent multiple AJAX requests with visual feedback, I need to safegu ...

The Android WebView experiencing issues with the functionality of the Hamburger Menu

I'm facing an unusual issue with the Android WebView in my app. The hamburger menu on my website works perfectly fine on my mobile browser, but when I try to open it in the Android WebView, it does not fully expand to show the menu items. I have trie ...

Ways to remove the default classes added by ngbootstrap

My current challenge involves utilizing ngbootstrap for popovers, yet desiring to override its default styling. Specifically, I have a form that should function as a popover triggered by a button click, and it needs to maintain its own distinct styles. Up ...

The addition of input fields on keyup creates problems in the initial field of each row

I am currently working with a table and attempting to calculate the sums as follows: td(1) + td(2) + td(3) = td(4), td(5) + td(6) + td(7) = td(8), td(9) + td(10) + td(11) = td(12). This is the code I have implemented: $(document).ready(function () { ...

Utilizing PHP and jQuery to dynamically populate Google Maps with multiple markers

I am currently working on integrating a Google map with a database to dynamically display multiple markers using PHP and MySQL. Below is the code I have been using: <?php //This section retrieves data from the database for later use in jQuery //CREATE ...

Jquery CSS malfunctioning on Post's div element

After retrieving a div using jquery's post method on my page, I am encountering an issue when attempting to apply CSS to the divs. Strangely enough, applying CSS with jquery to divs that are already present on the page works perfectly fine. Javascrip ...

Including additional data to a page after each iteration in order to display the current progress

I am currently working on a loop that iterates through the lines of a text area and processes each line sequentially. However, I am facing an issue where the page becomes unresponsive until all the data has been processed. Is there a way to dynamically u ...

Verify login availability using Javascript auto-check

For quite some time now, I've been grappling with a significant issue that has been consuming my attention. I am determined to implement an auto-check login availability feature in the registration form of my website. My goal is for it to verify the ...

"Exploring the world of Rails development, mastering Popups with Ajax for seamless deletes

Currently, I am working on a Rails project that features a standard Rails delete link within a popup. The challenge I am facing is that there are multiple popups present on the page. To manage this, I have implemented a hide action attached to the body (on ...

Unable to interpret the jQuery Ajax issue

My script is intended to send form data to a PHP script using ajax, but it's not working. I believe there is an error with $.ajax but I'm unsure how to locate and view the specific error. Currently, I have it set to alert 'fail' in case ...

Mapping Functions to HTTP Status Codes

I'm just getting started with my ajax-jquery learning journey. How does jquery determine the success or failure of a request? (When is success called versus when is error called?) I have a hunch that it has something to do with the HTTP status code ...