Dynamic paragraph tags do not scroll smoothly with jQuery Smooth Div Scroll

I'm currently in the process of creating a stock ticker and I am facing some difficulties with the Smooth Div Scroll plugin. My issue arises when trying to incorporate dynamically generated paragraph tags - instead of forming a horizontal scrolling list, the P tags are simply displayed vertically on the page. Interestingly, when the paragraph tags are added statically, they function as intended by being positioned correctly and scrolling smoothly. Upon comparing the static version with the dynamic one using Firebug, it seems that the HTML remains the same, leading me to suspect that this may be a CSS-related problem which I have been unable to resolve.

EDIT: Feel free to check out the jsFiddle

Do you have any suggestions or solutions to offer?

Below is the code snippet for reference:

$(window).load(function () {
        var $divScrollableArea = $(".scrollableArea");
        var $stocks = new Array("GOLD", "SSRI", "PTM", "PAL", "USD", "SH", "DJI");

        $.each($stocks, function (index, item) {
            var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22" + item + "%22)%0A%09%09&&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
            $(function () {
                var jqxhr = $.getJSON(url, function (json) {
                    $divScrollableArea.append("<p>" + item + "<br /><span class='left'>" + json.query.results.quote.BidRealtime + 
                        "</span><span class='right'>" + json.query.results.quote.Change_PercentChange + "</span></p>");
                })
                .success(function () { BuildScroll(); });
            });
        });

        function BuildScroll() {
            $("div#scrollingText").smoothDivScroll({
                autoScroll: "always",
                autoScrollDirection: "endlessloopright",
                autoScrollStep: 1,
                autoScrollInterval: 15
            });
        }
    });


<style type="text/css">
    .stock
    {
        font: bold .8em Verdana;
        padding: 5px;
        width: 100%;
    }
    .innerStock
    {
        float: left;
        margin-right: 20px;
    }
    .left
    {
        font: normal .7em Verdana;
        text-align: left;
        width: 30%;
        padding-right: 15px;
    }
    .right
    {
        font: normal .7em Verdana;
        text-align: right;
        color: red;
    }
    #scrollingText
    {
        width: 100px;
        height: 35px;
        border: solid 1px #ccc;
        position: relative;
        padding: 2px 0px;
    }

    #scrollingText div.scrollableArea p
    {
        display: block;
        float: left;
        margin: 0;
        padding-right: 7px;
        padding-top: 1px;
        font-family: Courier, Arial, Sans-Serif;
        font-size: 12px;
        line-height: 12px;
        font-weight: normal;
        background-color: #fff;
        color: #000;
        white-space: nowrap;
        width:300px;
    }
</style>

<div id="scrollingText">
    <div class="scrollWrapper">
        <div class="scrollableArea">
        </div>
    </div>
</div>

Answer №1

It appears that the issue at hand is related to CSS.

In particular, the width of #scrollingText (100px) is causing line breaks. To resolve this, consider removing this attribute or adjusting the paragraph widths accordingly.

If you prefer to maintain the fixed size of #scrollingText, you will need to define styles for div.scrollWrapper as follows:

div.scrollWrapper {
    display: block;
    width: 800px;
}

Ensure that the width exceeds the total sum of all paragraph widths within it. I have made updates to your fiddle (including adjustments to paragraph widths): http://jsfiddle.net/RZBUJ/2/

Answer №2

modify your css

<style type="text/css>
    .stock
    {
        font-weight: bold;
        font-size: 0.8em;
        padding: 5px;
        width: 100%;
    }
    .innerStock
    {
        float: left;
        margin-right: 20px;
    }
    .left
    {
        font-style:normal;
        font-size: 0.7em;
        text-align: left;
        width: 30%;
        padding-right: 15px;
    }
    .right
    {
        font-style: normal;
        font-size: 0.7em;
        text-align: right;
        color: red;
    }
    #scrollingText
    {
        width: 400px;
        height: 80px;
        border: 1px solid #ccc;
        position: relative;
        padding: 2px 0px;
        overflow:auto;
    }

    #scrollingText div.scrollableArea p
    {
        display: block;
        float: left;
        margin: 0;
        padding-right: 7px;
        padding-top: 1px;
        font-family: Courier, Arial, Sans-Serif;
        font-size: 12px;
        line-height: 12px;
        font-weight: normal;
        background-color: #fff;
        color: #000;
        white-space: nowrap;
        width:300px;
    }
</style>

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

Avoiding interference with adjacent elements caused by long content in a div

Hey there, I could really use some help with my CSS layout, I'm pretty new to CSS and Flexbox and I'm trying to create a simple layout. The issue I'm running into is how to stop long content inside a pre tag from pushing other divs. Here& ...

Tips for styling an asp:DropDownList to resemble a bootstrap dropdown list without relying on the form-control class

As I work on updating an old application with Bootstrap styling, one challenge that keeps arising is how to style an asp:DropDownList to look like a Bootstrap dropdown. I found a helpful Stack Overflow post suggesting the use of the form-control class. Wh ...

having difficulty retrieving information from ejs to controller and client-side JS

I am new to working with node and express. Currently, I am developing an application that includes a login feature. While I have successfully implemented user registration, I am encountering difficulties when attempting to log in a user. Below is my code, ...

Tips for creating a div that slides from the right side to the left side

I received a code from someone and I need help with making the sliding div slide from right to left. Essentially, I want the div to hide on the right side and slowly move to the left within a width of 300px. Here is the HTML code: <a id="loginPanel"&g ...

Tips for aligning a form input and button in the same row without any spacing between them (keeping all elements the same size)

Can anyone help me with styling an input and button using bootstrap so that they take up the full width automatically, with margins only on the left, right, and top of the elements but no padding or margin in between them? I want the input field and button ...

The functionality of an external Javascript library fails to operate properly once the website is deployed to a hosting

Encountering a peculiar bug with my website at . The website is supposed to load both the JQuery and EasyUI libraries. JQuery is loading correctly as a function to print out "ready" when the page loads. The issue arises when trying to drag products onto th ...

Error in Developer Console: Incorrect CSS Selector Output

While using the developer console in Firefox or Chrome, I noticed that when typing $('a'), it does not always return an array of all the links on a page as expected. Strange enough, sometimes it only returns a single a element instead of multiple ...

The $.ajax method seems to be experiencing some issues, but fortunately, the $.getJSON

I'm in the process of retrieving the share count for Pinterest and the following code is functioning effectively: var pi_like_count = 0; PIUrl = "https://api.pinterest.com/v1/urls/count.json?url=" + url1 + "&format=jsonp" + '&callback=? ...

Display words on screen and then alter hue using HTML and CSS

Is there a way to dynamically change the color of text inside <a> tags from black to red after a specific time interval and keep it permanently red? do { document.getElementById("code").innerHTML +="<a>Hello World</a><br>"; awa ...

When an icon is hovered over in Vue, a text box popup will be displayed

Working on a personal project that requires obtaining the status of all devices within a unit. The status, along with the device name, is returned in an array from the function deviceStatus(). If all devices are currently marked as ON, the home icon next t ...

Full-screen background with image adhering perfectly - left-aligned button that stays in place

Excuse me if my question seems basic, as I am just starting out in front-end development and may not know all the necessary terms to fully understand existing questions. I currently have a simple html file that consists of a title and three buttons, with ...

Choose from a dropdown menu to either activate or deactivate a user account

I'm new to php and I need help getting this code to function properly delete.php <?php include_once 'dbconfig.php'; if($_POST['del_id']) { $id = $_POST['del_id']; $stmt=$db_con->prepare("UPDATE tbluse ...

Picture leading to the expansion of a table cell's height

I despise CSS more than anything. My table header with multiple inline table cells was working flawlessly until I attempted to add an image to one of the cells, causing the div's height to inexplicably expand. Here's an example of the blank tab ...

Troubleshooting Hover Problem with D3 Chord Example on Internet Explorer 11

I came across an interesting tutorial on how to create chord diagrams in D3, which I'm currently experimenting with. The tutorial can be found at One example that caught my attention is about hair color preferences. When you hover over a group on the ...

Toggle between hiding and showing div elements issue

Currently in the final stages of developing an iPhone web app, I have encountered a small issue that needs to be resolved. I have successfully hidden one layer and displayed another with a button click. However, what I am aiming for is to toggle between s ...

Unexpected behavior with first-child selector in a simple CSS code

It seemed so clear to me, but it turns out I was mistaken. Check out this link $('p:first-child').css({color:'red'}); The color of all text is not being altered. <div class="post text"> <a href="#">this is a url</a> ...

The positioning of the Bootstrap 4 sidenav on mobile devices is different from the left side

Hey there! In my current project, I've got a left sidebar that contains various menu items. The code for my sidebar looks like this: html { height: 100%; } body { min-height: 100vh; } /* fixed and fluid only on sm and up */ @media (min-widt ...

Attempting to trigger the timer to begin counting down upon accessing the webpage

Take a look at this example I put together in a fiddle: https://jsfiddle.net/r5yj99bs/1/ I'm aiming to kickstart as soon as the page loads, while still providing the option to pause/resume. Is there a way to show the remaining time as '5 minute ...

Guide on integrating an event in Angular 4 to an HTML element inserted using an external library

Recently, I integrated the jQuery wizard library into my project to streamline user interactions. One of the key features it provides is automatically adding next and back buttons to guide users through the wizard process. You can find more information abo ...

Creating a Javascript function to turn lights off using CSS manipulation, similar to the feature found

Is there a way to use JavaScript to obscure all elements on a page except for one specific HTML element? This web application is optimized for Chrome, so CSS3 can also be utilized. ...