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

后端 未结 4 1944
伪装坚强ぢ
伪装坚强ぢ 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 06:54

    you could do something like this

    this is the scrolling text

    and a js function

    function scroll() {
      $('#scrolltext').css('left', $('#scrollcontainer').width());
      $('#scrolltext').animate({
        left: '-='+($('#scrollcontainer').width()+$('#scrolltext').width())
      }, 2000, function() {
        scroll();
      });
    }
    
    scroll();
    

    tested. can be found here: http://jsfiddle.net/zrW5q/85/

提交回复
热议问题