The compatibility between fittext.js, jquery fadeIn, and responsive text is not optimal

I recently implemented fittext.js to make my text responsive on a website. I have 3 divs that are hidden until their corresponding link is clicked. Each div contains an h2 tag, but I'm facing an issue with the text not showing up when I use the fade-in effect. Can someone please help me resolve this?

Here is the HTML code:

<a id="one" href="#">one</a>
<a id="two" href="#">two</a>
<a id="three" href="#">three</a>

<div class="one content">
    <h2>one</h2>
</div>
<div class="two content">
    <h2>two</h2>
</div>
<div class="three content">
     <h2>three</h2>
</div>

CSS styling for the content:

.content {
    background: red;
    width: 500px;
    height: 100px;
    margin: 10px;
}
.content {
    display: none;
}
h2 {
    font-size: 60px;
    height: 100%;
}

JQuery function for handling the click event and fade animation:

$("a").click(function() {
        var cls = $(this).attr('id')
        $(".content").fadeOut(100);
        $('.' + cls).delay(100).fadeIn(400);
        return false;
    });


jQuery("h2").fitText();

If you want to see the code in action, check out this jsFiddle link.

Answer №1

Explanation: If you use .content {display: none;}, the fitText function won't be able to apply the JavaScript onload because the element is hidden. There could be a solution for this issue, but it's uncertain at this stage. :)

Answer №2

It seems like the h2 tag has a font size of 0, which is being added from an unknown source.

If you encounter this issue, here are some steps you can take:

.content {
   background: red;
   height: 100px;
   margin: 10px;
   font-size:60px;
   width: 84%;
   max-width:500px;
}

http://jsfiddle.net/g76G9/4/

Answer №3

I have developed a fiddle that utilizes opacity instead of display:none. This method achieves the same effect as before, but it allows fitText to function correctly!

http://jsfiddle.net/k89D5/21/

<a id="alpha" href="#">alpha</a>
<a id="beta" href="#">beta</a>
<a id="gamma" href="#">gamma</a>

<div class="container">
    <div class="alpha content">
        <h2>alpha</h2>
    </div>
    <div class="beta content">
        <h2>beta</h2>
    </div>
    <div class="gamma content">
         <h2>gamma</h2>
    </div>
</div>;

.content {
    background: blue;
    width: 600px;
    height: 120px;
    position:absolute;
    top:0;
    left:0;
    transition: opacity 0.5s ease-in-out 0s;
}

.container{
    margin: 15px;
    width:600px;
    height:120px;
    position:relative;
}

.content {
    opacity:0;
}

h2 {
    font-size: 70px;
    height: 120%;
}

$("a").click(function() {
        var id = $(this).attr('id');
        $(".content").css('opacity', '0');
        $('.' + id).css('opacity', '1');

        return false;
    });

jQuery("h2").fitText();

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

Learn how to fetch user-selected options in Node.js and display the corresponding file contents in a textarea after submission

Hello, I am new to Node.js so please be patient with me. I am struggling to figure out how to retrieve the selected option from a drop-down list after a user submits it and then perform an action based on that choice. Here is an example of what I have in m ...

Tips for making floated divs expand the width of the parent div

I am in the process of creating a new webpage and I would like to incorporate a slider that moves from left to right. Within a section, I have a div containing three floated articles. My goal is for the (wrapper) div to expand its width so that the inner a ...

Ways to align radio buttons vertically

I am currently working with three radio buttons that are initially aligned horizontally, but I would like to change their alignment to be vertical instead. What is the best way to achieve this? * { margin: 0; padding: 0; box-sizing: border-b ...

How can I use Asp.net to convert an HTML page into mht using .net?

Similar Question: Generating MHTML from HTML I am looking to convert an HTML page to MHT format using C# .NET. Are there any .NET libraries available for this task? I'm in need of a library, whether it's free or paid. ...

Display the initial child of an element that does not have a particular class with the help of

In my latest coding experiment, I am attempting to display the first child of an element that does not possess the "submitted" class. As a result, I wrote something like this: $('#menu li:first-child:not(".submitted")').show(); Within the HTML ...

What could be causing the lack of functionality when defining a CSS role using :host ::ng-deep within an Angular component's stylesheet?

My knowledge of Angular and CSS is limited, and I am facing a problem when trying to define a CSS style for a specific component in the .css file. If I use the following code snippet: .p-column-title { display: none; } it works perfectly. However, wh ...

Enlarge the image to fill the entire screen

Currently, I am working on a webpage where I am displaying data fetched from a database using Laravel framework. The code snippet is shown below: Here is how the webpage looks like - image1 What I aim to achieve is to make the div go fullscreen upon clic ...

Display the text after passing the jQuery validation test

Currently, I have successfully implemented the jquery.validate.js plugin and it is functioning properly. However, my goal is to display text in a hidden div only when validation is successful and the form has been submitted. $("#commentForm").validate(); ...

What is the best way to assign a different set of sub tabs to each individual tab?

Upon hovering over MTH025-ENG111, I would like it to become visible. Any additional tips or tools you have to assist me with this are greatly appreciated. <html> <head> <title> join the club </title> </ ...

Simple guide on how to use AJAX (without jQuery) and PHP to count the number of records

As a novice programmer, I am attempting to tally the number of records in a table. Despite perusing various code snippets, I am unable to seamlessly integrate them to pass the PHP result to my javascript code. Here is the current state of my code: showsca ...

Analyzing the data consumption of an Ajax response in text format

Currently, I am receiving an Ajax Response Text from a PHP Server. Imagine that the response text is made up of 20 characters. (for example: echo "asdhfgyd dhrjtjsjtjr";) This roughly equals (20/1024) KB. My issue lies in the fact that when using a stan ...

Bootstrap HTML - Medium-Sized Device Recognized as Large on Registration

Encountering some troubles with Bootstrap's Grid system on various devices. According to documentation, column sizes are based on window size: Extra small 576px , Small >= 768px , Medium >= 992px , Large >=1200px However, a medium devic ...

Retrieving the following element

I am trying to retrieve the next sibling element of one that contains the text "Yes". Unfortunately, I can only use the text "Yes" and part of the id attribute, as the number (e.g.. 106) is not available. Due to this limitation, I am unable to directly acc ...

Display an image file using the <img src=""> tag in PHP

I am facing a small issue and could use some assistance. My goal is to display the ROW image associated with each unique ID in my database. Below is an excerpt from my PHP code: while ($row = $result->fetch_assoc()) { // Display the image ...

I'm curious about how I can determine the reason why my badge is not accepting HTML tags in its tooltip

My goal is to integrate a bootstrap badge-alert with an HTML tooltip. I am following the example provided at https://getbootstrap.com/docs/4.3/components/tooltips/ Despite my efforts, when using the code snippet below, the tooltip appears but the HTML tag ...

Using Angular 4 to retrieve a dynamic array from Firebase

I have a dilemma while creating reviews for the products in my shop. I am facing an issue with the button and click event that is supposed to save the review on the database. Later, when I try to read those reviews and calculate the rating for the product, ...

Create a distinct CSS border radius

My goal is to create the pink section using border radius. However, when I apply border radius, it begins from the very edge of the container div, leaving about 1cm of flat or solid pink before the border radius starts. ...

Dynamic content displayed within adjacent div elements

I am currently working on a project where I am dynamically generating an outline by creating panels and labels in ASP.NET. Each node in the outline is defined by an outline number and outline text, which are obtained from a database that defines the relati ...

When utilizing jQuery post to send data to a node.js server, the request is abruptly terminated before completion

When sending a post request to my node.js server, I use the following code: $.post("/admin/google",{result: result, testName: testName}, function(data){ console.log(data); if(data.status === 200) { alert ...

Organize the flexbox order: I would like the box to be positioned below an element that is not a direct sibling

Is there a way to ensure that the yellow box is placed below the blue box on smaller screen sizes? I have realized that since the yellow box is not a sibling to the other boxes, it does not behave as expected. How can I rectify this issue? Link to JSFidd ...