jquery / css: make text inside div scroll horizontally like a news ticker no plugin

后端 未结 4 1938
伪装坚强ぢ
伪装坚强ぢ 2021-02-09 06:26

anyone have some tips on how to make text inside a div scroll horizontally from right to left in a \"news ticker\" fashion without having to use a plugin. Here is an example of

4条回答
  •  悲哀的现实
    2021-02-09 07:03

    Here's a quick solution to this: http://jsfiddle.net/4mTMw/8/

    var marquee = $('div.marquee');
    marquee.each(function() {
        var mar = $(this),indent = mar.width();
        mar.marquee = function() {
            indent--;
            mar.css('text-indent',indent);
            if (indent < -1 * mar.children('div.marquee-text').width()) {
                indent = mar.width();
            }
        };
        mar.data('interval',setInterval(mar.marquee,1000/60));
    });​
    

    Using the text-indent css property, you can do this rather simply.

提交回复
热议问题