开发者

Use a marquee in a div only if there is overflow?

开发者 https://www.devze.com 2023-03-09 22:16 出处:网络
I want to scroll text (marquee) in a div tag ONLY when the text overflows. I have the marquee setup, and I am using the jQuery Marquee plugin. Everything works beautifully with the marquee, but I don

I want to scroll text (marquee) in a div tag ONLY when the text overflows.

I have the marquee setup, and I am using the jQuery Marquee plugin. Everything works beautifully with the marquee, but I don't need it to scroll if the text fits on one line.

The page where I am working is here: http://lbr开发者_StackOverflow中文版annonent.com/BigCountry247/index.html. The "Title", "Artist", and "Up Next" scrolling fields all need to only scroll if there is overflow.

Any ideas?


Here is the working demo that i made for your question. It should give you the idea what to do.


If you're already using jQuery, consider this:

$(".marquee").each(function() {
  if($(this).prop('scrollWidth') > $(this).parent().width())
    $(this).wrap('<marquee></marquee>')
});

Give the divs you only want to have scrolling on overflow the class marquee instead of using a marquee tag, and as long as that's before any other code that manipulates the marquee (event handler assignment I assume) it shouldn't matter what else you're doing with it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号