Display text in a scrolling manner once it exceeds the container's boundaries

I've been searching high and low for a solution to my problem. I have a div that displays the information about who's playing on an online radio station.

The width of the div is set to 200px, but when the artist and song title are too long, the text gets cut off due to overflow:hidden property being applied.

I am looking to create a scrolling effect where the entire text moves from left to right, allowing the right side of the text to become visible as the left side goes outside the boundaries of the div. Can someone please guide me in the right direction?

Thank you!

<div class="radioco_song">EBTG - Driving (The Underdog Remix)</div>

and

.radioco_song {
font-size: 16px !important;
white-space: nowrap;
width: 200px;
overflow: hidden;
border: 1px solid #ccc;
padding: 10px;
}

Answer №1

Here is a solution that may meet your needs:

function beginScrolling() {
  var itemWidth = $(this).width();
  var parentWidth = $(this).parent().width();

  if (itemWidth > parentWidth) {
    var distanceToScroll = itemWidth - parentWidth;
    var parentItem = $(this).parent();
    parentItem.stop();
    parentItem.animate({
      scrollLeft: distanceToScroll
    }, 3000, 'linear');
  }
}

function stopScrolling() {
  var parentItem = $(this).parent();
  parentItem.stop();
  parentItem.animate({
    scrollLeft: 0
  }, 'medium', 'swing');
}

$('#menu a').hover(beginScrolling, stopScrolling);
#menu {
  margin: 10px;
}

#menu > div {
  width: 100px;
  overflow: hidden;
  font-family: sans-serif;
}

#menu > div a {
  white-space: nowrap;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="menu">
  <div><a href="#">Short</a></div>
  <div><a href="#">Some really long link text here...</a></div>
  <div><a href="#">Another really, really, really long piece of text here</a></div>
</div>

Fiddle by : bryanjamesross

Answer №2

To modify it, simply update the overflow property to scroll: .

melodyjam_song { font-size: 14px !important; white-space: nowrap; width: 180px; overflow: scroll; border: 1px solid #888; padding: 8px; }

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

What is the process for sending the selected checkbox text to an action result on a Razor page?

Working with asp.net core razor pages, I am passing the selected id as an array successfully. However, the issue arises when the selected text value for the checkbox is not being passed or displayed. The problem seems to be occurring on this line of code ...

Learn how to retrieve the ID of an element with a simple click using PHP, jQuery, AJAX, and Javascript

Apologies for being a newbie in this field, but I'm eager to learn. Any assistance would be greatly appreciated. In my project, there is a sidebar with rss links that I want to incorporate ajax functionality into. So, whenever a user clicks on a link ...

Exploring the semantics of CSS documents

Picture this scenario: I have a massive CSS file with over 40,000 lines, like the one found at https://cdn.jsdelivr.net/npm/[email protected] /dist/semantic.css I need to sift through this file and specifically search for class definitions that inclu ...

The functionality of HTML labels may be limited when used in conjunction with AJAX

I am using Ajax to load an HTML page and encountering a problem with the label not working properly when associated with a checkbox. Here is the data: <input type="checkbox" name="dis_net" id="dis_net" value="1" /> <label for="dis_net">Test< ...

Identifying and categorizing flip switches with jQuery without relying on div elements

Is it possible to have two jQuery flip switches side by side, but only one visible if the screen is too narrow? I've tried assigning different classes to each switch for styling purposes, but it doesn't seem to work correctly. When I assign a cl ...

iOS creates dynamic images with artifacts that appear on a generated and animated canvas

I am currently developing an HTML5 web application for WeChat, compatible with both iOS and Android devices, using only pure JavaScript without any third-party libraries like jQuery. The main feature of my app involves creating visually appealing animation ...

Making jquery's one() function work effectively with duplicated classes

Take a look at the following HTML code snippet: <div class="options-selecter"> <span class="item-option" data-value="8">XYZ</span> <span class="item-option" data-value="11">LMN</span> <span class="item-option a ...

Easily move a div by dragging and dropping it from one location to another

Looking to seamlessly transfer a div from one container to another. I've got the CSS and HTML code ready for you to assist me, here is the snippet: <!DOCTYPE html> <html> <head> <style type="text/css"> #my ...

When combining <a> with the class line-through, the line does not appear

I am currently utilizing a class to replace the deprecated strike in HTML: .entfall { text-decoration: line-through; } However, when using Firefox 38.x and the following code: <span class="entfall"><a href="some link">text</a></span ...

Use JavaScript to generate an HTML element that has an attribute mirroring its text content

Trying to figure out how to create an HTML element similar to this: <option value="Replaced">by this</option> For example: <option value="ThisIsTest">ThisIsTest</option> UPDATE Using jQuery, I need to achieve something like thi ...

Tumblr post not automatically playing flash content

I am facing an issue with embedding a flash object on my tumblr blog (Billy's audio player) where I have to click a white play button for the object to work properly. This problem seems to occur specifically in Chrome and Edge browsers, as other websi ...

Is there a way to have a fixed width div positioned in the center of the screen, with two additional divs on either side

I have come across this stunning image: https://i.stack.imgur.com/tUYMc.png It serves as a header for a website - click on it to see the full size. I am trying to replicate this using HTML, CSS, and images, but I'm struggling. It needs to be 100% w ...

What was the recommended dimensions for CSS containers in 2018?

In the realm of responsive layout design, what is the recommended size for a max-width container as of 2018? My current choice is to use 1140px, which I find works well with the standard screen size of 1366px. ...

Enhancing the existing site with a new sidebar column in the HTML layout

My website has a structure like this: <body> <div id="header">...</div> <div id="content">...</div> <div id="footer">...</div> </body> The layout consists of floats, clears, margins, and paddings in t ...

Tips for Smoothing Out Your jQuery LavaLamp Effect

I'm currently developing a jQuery function to implement the "lavalamp" effect on my navigation bar. Everything seems to be working smoothly, except for one issue. If you hover over an item (e.g., Community Service) and then move your mouse away from ...

Tips for shifting a div to the left with AngularJS

I am working with a div structure that looks like the following: <div class="col-xs-1 scroll-button"><i class="glyphicon glyphicon-chevron-left"></i> </div> <div class="customer-ust-bant col-xs-22" id="letters"> <box n ...

What is the best way to target an input element with a specific ID using JQuery Mobile?

For instance, <input type="button" id="one" value="o" data-role="button" data-inline="true" class="game"/> I aim to utilize this button in a manner where I can access its value using the ID, like for updating the value. Is there a way to reference ...

What is the best method for implementing free timeslots in fullcalendar using jquery?

I need help figuring out how to incorporate free timeslots in fullcalendar from 16:00 to 20:00 each day. These times should be available for users to book events but should not overlap with existing events fetched using a JSON call. The database query for ...

Tips for adjusting the order in which styles load in NuxtJS

I need to adjust the loading order of styles in my current project. In my custom stylesheet style.css, I've made some overrides, body { font-family: "Lato", sans-serif; font-size: 14px; font-weight: 400; font-style: normal; ...

Utilizing HTML and CSS for Optimal Page Layouts

<div id="pageHeading"> <h1>zisland</h1> <img src="islandpic.jpg" alt="Mountain View" style="width:50px;height:50px"> </div> #pageHeading{ color: #000000; width: auto; height: auto; text-align: center; ...