Unusual findings encountered while working with FitText.js

Experiencing challenges while using FitText.js - I have set up the script in my <head> section like this (I've included all details for context, planning to streamline it later):

<script type="text/javascript">
            $(document).ready(function() {

            var $container = $('#thumbnail-array');

                $container.imagesLoaded(function() {
                    $container.masonry({
                        itemSelector: '.video-thumbnail',
                        columnWidth: '.grid-sizer',
                        gutter: '.gutter-sizer',
                        percentPosition: true
                    });
                });
            });

            jQuery(document).ready(function() {
                jQuery('.mobile-close').click(function(e) {
                    jQuery(this).toggleClass('active');
                    jQuery('.mobile-nav').toggleClass('active');

                    e.preventDefault();
                });
                jQuery('.dropdown').click(function(e) {
                    jQuery(this).toggleClass('active');
                    jQuery('.mobile-nav').toggleClass('active');

                    e.preventDefault();
                });
                $(".fittext1").fitText(1.1);
                $(".fittext2").fitText(0.75);
            });

            $(document).ready(function() {
                $('.overlay').hover(function(){
                    $(this).parent().find('video').get(0).play();
                }, function() {
                    var video = $(this).parent().find('video').get(0);
                    video.pause();
                    video.currentTime = 0;
                });
            });

        </script>

The key aspect here is probably this part:

$(".fittext1").fitText(1.1);
$(".fittext2").fitText(0.75);

Subsequently, I'm applying it to two elements, <h5> and <h6>, defined in my CSS as shown below:

h5 {
    display:inline;
    font-size: 2em;
    margin-bottom: 0px;
    padding-bottom: 0px;
}

h6 {
    display:inline;
    font-size: 0.75em;
    letter-spacing: 0.3em;
    padding-top: 0px;
    margin-top: 0px;
    font-weight: 100;
}

and referenced in my HTML like this:

<h5 class="fittext1">Title</h5>
<hr>
<h6 class="fittext2">Subtitle</h6>

However, despite expecting them to scale with the parent element, something seems amiss and it's difficult to pinpoint the issue! You can see what's happening here.

I've tried various approaches but haven't been able to achieve consistent text scaling or proportionate resizing on hover effects!

Initially, I targeted the .fittext1 and .fittext2 elements using #ID but switched to class due to multiple instances, yet the problem persists.

If you have any insights into what might be causing this behavior, please share!

Answer №1

After some investigation, it became apparent that FtText.js does not function properly with inline or span elements according to the project's GitHub page. The element that FitText.js is applied to (not a wrapper or container!) must be either positioned as absolute, block or inline-block.

To resolve this issue, I changed my <h5> and <h6> tags to have a display property of inline-block;

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

unable to execute react scripts

npm log 0 info it worked if it ends with ok 1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ] 2 info using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e001e032e58405f5c405e ...

Solution: Resolve clientY scrolling issue within an HTML document

I am facing an issue with the positioning of my context menu. When I right-click and scroll down, the menu does not maintain its regular position. Instead of appearing to the right of the mouse cursor when stationary, it moves below the cursor based on how ...

Execute a Node.js script on Windows in the background upon user login by creating a Run key

My operating system is Windows Server 2012R2. I have a node.js script that needs to be executed when a user logs in. To achieve this, I am configuring the command to run in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVers ...

What is the best way to eliminate an object from an array by using Lodash?

Seeking assistance in removing an object from an array using Lodash. Within server.js (utilizing NodeJS): var lodash = require('lodash')(); var rooms = [ { channel: 'room-a', name: 'test' }, { channel: & ...

Adjust the size of a container to fit another container nested within it

I am facing challenges when it comes to resizing a div with the ID mask that is used in conjunction with a scrollTo() effect. The #mask is set to occupy 100% of the browser window on both sides and has an overflow: hidden property. This means that when I ...

Show the quantity of chosen selections utilizing ng-select

I have implemented the ng-select component for users to select multiple options from a list. My goal is to have the selected option displayed normally when only 1 option is chosen. However, if 2 or more options are selected, I want a custom template to sh ...

Can we use CSS to animate the enlargement of an element without moving it?

Take a look at this jsFiddle. With CSS animations gaining popularity, I am interested in creating an effect where an element (.box) expands with an animation when the mouse hovers over it. The challenge is to keep the center of the element fixed while enla ...

Use CSS Grid to anchor the final element to the right side of a horizontal navigation menu

I am facing an issue with my horizontal navigation bar that contains a dynamic number of links. In this specific case, there are 3 links displayed below: https://i.sstatic.net/f5vcn.png My goal is to keep the first two links in their original position an ...

Creating a file object in NodeJS with a specific file path - a step-by-step guide

Is there a way to create a File object in NodeJS using the path of an existing file, similar to how it can be done on the client side? In other words, is there an equivalent function in NodeJS to achieve the following: function srcToFile(src, fileName, mi ...

Viewing the availability of various locations within a JSON table based on the user's specific locale

I am working with a JSON table: [ { "fr": { "name": "chien", "name_plurial": "chiens" }, "en": { "name": "dog", "name_plurial": "dogs" } }, { "fr": { "name": "chat", "name_plurial": "chats" }, "en": { "name": "cat", "name_plurial": " ...

Troubleshooting NPM installation failures with SQLite build

After updating to macOS Mojave and installing the latest versions of node 12.1.0, npm 6.9.0, brew 2.1.1, and Python 2.7.10 on darwin, I encountered an issue while running npm install in a package.json file for a project that includes "sqlite3": "4.0.6". ...

Counter Fails to Increase When Items are Added to Cart

Hello there! I recently ran into a coding issue while trying to remove the side bar cart popup on my website. After making some modifications, I noticed that the item counter in the cart no longer increments when using the quick add button. Oddly enough, t ...

Is there a way to determine if scroll events are triggered just once, similar to how they are on touch devices?

When it comes to iOS devices (and possibly Android ones), the scrolling behavior is quite different. The scroll event is triggered only once after the entire scroll process has been completed. Is there a way for me to determine if the browser follows this ...

What is the method for including line numbers alongside a highlighted code section in highligh.js?

I want to ensure that the text rows are aligned perfectly with the numbers in the yellow vertical bar, without causing any issues with the mouse pointer as it moves across the rows. Adjusting margin or padding also affects the position of the mouse pointer ...

Using jQuery: how can we animate an upward movement?

I currently have a vertical list of DIVs and I am able to use the .fadeOut() method to remove one of the middle DIVs. However, I am unsure how to generate a slow move-up effect for the remaining DIVs below the deleted one. Any advice on achieving this? ...

How come my blocks are spilling over into other blocks?

I have successfully created a webpage using Drupal 8 and Bootstrap, featuring a "Learn more" button to expand the details. However, I am facing an issue where the information blocks overflow when collapsed. The gray line and label are spilling into the up ...

Verifying the value associated with the "type" attribute of an input field

I need to create test cases for automation testing. My goal is to verify if the password fields in my form contain type="password" attribute for input elements... Is there a way to achieve this using jquery? Thank you. ...

secure usage of template variables in Tornado web tornado web template variable pipe safety

I have encountered an issue in my backend handler where I am sending a string with double quotes. Here's what it looks like: print '\"test\"' self.render('test.html', test = '\"test\"') In the templa ...

Arranging the arrow for custom sorting with w2ui.js

I am currently using w2ui and have implemented a custom sort function. While the sort function is functioning properly, I am facing an issue with the arrow not displaying in the table header. Specifically, I have applied my custom sort to the last name co ...

Node.js implementation to transfer MongoDB to CSV, with the unfortunate loss of certain columns

I have a script that exports a MongoDB table to CSV but I seem to be missing some columns. It appears that the column with many null values (where the first 100 rows are all null) is not being included in the exported CSV file. const mongodb = require(" ...