Utilizing Jquery to create a carousel with looping functionality for flowing text

I am currently facing an issue with a carousel that contains multiple images and text. In order to make the text responsive, I have implemented a script called FlowText. The script works perfectly on the initial carousel image (the active one), but as soon as the carousel moves, it fails to resize the text accordingly. I suspect that the issue lies in the fact that the script only runs once, and once the carousel moves, it ceases to function properly. How can I modify the script so that it dynamically resizes the text every time the carousel moves?

<div class="carousel slide" id="imageCarousel3" data-interval="2000"
 data-ride="carousel" data-pause="hover" data-wrap="true">

 <ol class="carousel-indicators">
 <li data-target="#imageCarousel3" data-slide-to="0" class="active"></li>
 <li data-target="#imageCarousel3" data-slide-to="1"></li>
 ... (remaining list items)
 <li data-target="#imageCarousel3" data-slide-to="14"></li>
 </ol>

<div class="carousel-inner" style="max-width: 946px; overflow: hidden; margin: 0 auto;">

    <div class="item active">
        <img src="/Content/Images/Slide21.jpg" class="img-responsive">
        <div class="flowtext1" style="width: 50%; height: 100%; top: 0px; right: 0px; position: absolute; background-color: rgba(0, 0, 0, 0.75);">
            <div class="carousel-caption" style="top: 0%; position: absolute;">
                <p style="font-family: 'Open Sans Light'; font-size: 1.9em; text-align: center; left: 20%;"><strong>DSM e-FRE</strong></p>
                <p style="font-family: 'Open Sans Light'; font-size: 1.5em; text-align: center;"><strong>Freight Management Systems</strong></p>
            </div>
            ... (remaining carousel content)
        </div>

    </div>

    <div class="item">
        <img src="~/Content/Images/Slide22.jpg" class="img-responsive">
        <div class="flowtext2" style="width: 50%; height: 100%; top: 0px; right: 0px; position: absolute; background-color: rgba(0, 0, 0, 0.75);">
            <div class="carousel-caption" style="top: 0%; position: absolute;">
                <p style="font-family: 'Open Sans Light'; font-size: 1.9em; text-align: center; left: 20%;"><strong>DSM e-HMS</strong></p>
                <p style="font-family: 'Open Sans Light'; font-size: 1.4em; text-align: center;"><strong>Haulage Management Systems</strong></p>
            </div>
            ... (remaining carousel content)
        </div>
    </div>

For the script section:

 @section scripts{
    <script src="~/Scripts/jquery.fittext.js"></script>
    <script src="~/Scripts/flowtype.js"></script>

    <script type="text/javascript">
        $(".flowtext1").flowtype();

    </script>

    <script type="text/javascript">
        $("#fittext1").fitText();
        $("#fittext2").fitText(1.2);
        $("#fittext3").fitText(1.1, { minFontSize: '10px', maxFontSize: '75px' });
    </script>

}

Lastly, here are the images attached. The first image carousel works fine, while the second one does not resize properly.

First Picture Carousel

Second Picture Carousel

EDIT: Changed from id to class as suggested.

However, the functionality is still not as expected. Even in the regular size (desktop) view, the text is extremely small now, except for the first slide.

Any suggestions or assistance would be greatly appreciated?

New Image

New Image Second

Answer №1

The issue lies in having two elements sharing the same ID. When using the jQuery ID selector -> $("#something")...., it will target the first element with that ID assuming it to be unique. To resolve this problem, consider using class instead of id.

HTML:

<div class="item active" ;">
        <img src="/Content/Images/Slide21.jpg" class="img-responsive">
        <div class="flowtext"  style="width: 50%; height:100%; top:0px; right:0px; position:absolute; background-color:rgba(0, 0, 0, 0.75); ">
            <div class="carousel-caption"  style="top:0%; position:absolute;">
                <p style="font-family:'Open Sans Light'; font-size:1.9em; text-align:center; left:20%;"><strong>DSM e-FRE</strong></p>
                <p style="font-family:'Open Sans Light';font-size:1.5em; text-align :center;"><strong>Freight Management Systems</strong></p>
            </div>
                <div class="carousel-caption" style="top:30%; left: 10%; position:absolute;">
                    <ul style="text-align:left; left:0%;">
                        <li style="font-family:'Open Sans Light';font-size:1.2em; text-align:left;"><strong>NVOCC</strong><br /><br /></li>
                        <li style="font-family:'Open Sans Light';font-size:1.2em; text-align:left;"><strong>Freight Consolidation</strong><br /><br /></li>
                        <li style="font-family:'Open Sans Light';font-size:1.2em; text-align:left;"><strong>Staff Transparency</strong><br /><br /></li>
                        <li style="font-family:'Open Sans Light';font-size:1.2em; text-align:left;"><strong>No Missed Billings</strong></li>
                    </ul>
                </div>
        </div>

    </div>

    <div class="item">
        <img src="~/Content/Images/Slide22.jpg" class="img-responsive">
        <div class="flowtext" style="width: 50%; height:100%; top:0px; right:0px; position:absolute; background-color:rgba(0, 0, 0, 0.75); ">
            <div class="carousel-caption" style="top:0%; position:absolute;">
                <p style="font-family:'Open Sans Light'; font-size:1.9em; text-align:center; left:20%;"><strong>DSM e-HMS</strong></p>
                <p style="font-family:'Open Sans Light';font-size:1.4em; text-align :center;"><strong>Haulage Management Systems</strong></p>
            </div>
            <div class="carousel-caption" style="top:30%; left:10%; position:absolute;">
                <ul style="text-align:left;">
                    <li style="font-family:'Open Sans Light';font-size:1.2em; text-align:left;"><strong>Haulage Movement Optimization & Advanced Electronic Planning</strong><br /><br /></li>
                    <li style="font-family:'Open Sans Light';font-size:1.2em; text-align:left;"><strong>Map Interface and Telemetrics</strong><br /><br /></li>
                    <li style="font-family:'Open Sans Light';font-size:1.2em; text-align:left;"><strong>e-HR (Driver Payroll Auto-Calc)</strong><br /><br /></li>
                    <li style="font-family:'Open Sans Light';font-size:1.2em; text-align:left;"><strong>Trailer Audit and Control</strong></li>
                </ul>
            </div>
        </div>
    </div>

JS:

 <script type="text/javascript">
        $(".flowtext").flowtype();
 </script>

Answer №2

I discovered a method to continuously run a specific script.

<script>
            $(document).ready(function () {
                var intervalFunction = setInterval(function () {
                    $(".flowtext1").flowtype();
                }, 500);
            });
</script>

This script will continuously execute the flowtype function every half a second. This allows for easy resizing of text when transitioning to a new slide.

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

"Transitioning from Bootstrap version 3.3.7 to the latest Bootstrap version 4.1.3

Everywhere I look, it says that Bootstrap 4.1 is compatible with Bootstrap 3, but when I update my project to the newer version, a lot of things stop working, such as this cookie consent feature. @{ Layout = ""; } @using Microsoft.AspNetCore.Http ...

Utilizing JSON with AJAX to dynamically fetch data on a separate webpage results in the page reloading despite implementing the e.preventDefault() method

Looking to retrieve a value on a new page and navigate without refreshing? I'm utilizing the POST method here along with JSON to fetch values. Still learning the ropes of this Ajax code! My goal is to move from the team.php controller page to team_d ...

What sets apart using "!=" from "=" in the Jade template engine when assigning a variable?

I am a beginner in NodeJS and JS, so please excuse me if this question seems simple. Recently, I came across an example in the ExpressJS documentation that showed how to utilize the Jade template engine. The example included the following lines: html h ...

When an element is set to a fixed position while scrolling, it causes the element to flicker

After implementing the jQuery plugin stickyjs on my website, I noticed a strange issue. While it works perfectly fine on my Mac, when using the mouse scroll wheel on my PC, the element blinks once rapidly as it reaches the top of the page. Interestingly, d ...

Updating the value of a key in an object is not functioning as expected

There is a single object defined as requestObject: any = { "type": 'type1', "start": 0, "size": 10, "keywords": ['abcd','efgh'], filters: [], } Next, attempting to change the value for keyword, I updat ...

The value returned when using $.css('transform') is incorrect and displays as "rotate"

Possible Duplicate: Retrieve -moz-transform:rotate value using jQuery Firefox 15 - Chrome: $('#img2').css('transform'); return => "rotate(90deg)" Firefox 16 $('#img2').css('transform'); return => mat ...

Troubleshooting HTTP Response Body Encoding Problem in Node.js

When making HTTP requests with the native 'http' module, unicode characters are not displayed correctly in the response body. Instead of showing the actual value, question mark characters appear. Below is a snippet of the code that I am working w ...

Using AJAX to add an event listener and passing parameters to a separate function

Short and sweet - I've got a loop that creates a series of dynamic buttons, and when one of them is clicked, I need to pass its id attribute to another file to generate a new page on the fly. Here's the code snippet: for (var i in data.contacts ...

Tutorial on inserting a picture into muidatatables

Important Note: The image stored in the database is called "profileImage." I am looking to create a dynamic image object similar to other objects. When I input this code: { label: "Image", name: "profileImage" }, it simply displays the image endpoint as ...

Exploring the font variables in the asset pipeline of Rails 7

Creating a habit of defining a set of root variables is crucial for maintaining consistency throughout an application. :root { --main-font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif; --kbd-font-family: Consolas, "Libe ...

Adding some extra space inside a flex container using Bootstrap's padding

When attempting to use padding within a d-flex container to separate elements that are placed inline due to the d-flex class, I encountered an issue where the padding was not being applied and did not change anything. If I do not utilize the d-flex class, ...

Can process.env.NODE_ENV be found within Azure App Service?

I am integrating NodeJS with my Angular application using ExpressJS. I came across an npm package called norobot that I want to install in order to utilize the process object. I need guidance on how and where to set the NODE_ENV in an App Service on Micro ...

``There is an issue with getServerSideProps when wrapping it in a

When attempting to implement an auth handler function around getServersideProps, I encountered the following error message: TypeError: getServerSideProps is not a function The wrapper code in question is as follows: export async function protect(gssp) { ...

Can someone guide me on the proper way to utilize jQuery Masonry reload function?

The following script fades out tiles on the page that do not match the user's input. While this functionality is working perfectly, I am facing an issue where Masonry does not realign the tiles after they fade out. Sample HTML Code- <article clas ...

Struggling with implementing ng-repeat in AngularJS for displaying HTML content

I stumbled upon a post that covers pretty much what I'm trying to achieve: AngularJS - Is it possible to use ng-repeat to render HTML values? Currently, the code appears like this and displays correctly as text: <div ng-repeat="item in items.Item ...

What is causing the classList function to throw an error: Uncaught TypeError: Cannot read properties of undefined (reading 'classList')?

There's an error that I can't figure out: Uncaught TypeError: Cannot read properties of undefined (reading 'classList') console.log(slid[numberArray].classList) is working fine, but slid[numberArray].classList.add('active') is ...

Navigating to a different page in the app following a document update: a step-by-step guide

I am facing an issue with a page where I am trying to print a specific DIV using the script below... function printReceiptDiv() { var divElements; if (vm.isDLR) { divElements = document.getElementById("DLRreportCont ...

Error: Unable to locate corresponding closing tag for "<%"

I'm struggling to figure out what I might have missed. Everything appears correct, but the nested and somewhat complex code that I am writing seems to be causing an issue with EJS. The variable posts has been passed from node.js to the EJS file. How c ...

What steps do I need to take to set up Vue-CLI 3 to generate a webpage with no JavaScript?

My dilemma is this: I have a simple static page that does not require JavaScript. Using vue-cli 3, I am attempting to pass the HTML file through webpack for minification purposes. Unfortunately, it seems that accomplishing this task is not as straightforwa ...

Issue with Codeigniter's AJAX functionality causing div reloading to not function as intended

I am currently facing an issue where I can display text directly from the database on a webpage. However, when I edit the text in the database, I want it to automatically reload and show the updated text without having to refresh the entire page. Unfortun ...