English 中文(简体)
News Ticker - Premature Reconstruction
原标题:News Ticker - Pre-mature restart

我试图让这一新闻标准发挥作用。 出于某种原因,它将在第2个清单项目之后重新启动,这不是我所希望的——我希望在项目结束之前通过清单项目进行轮换。 这一说法有什么错误?

Here s a JSFiddle

HTML

<h1>This runs differently than the ticker for some reason. It s highly annoying in my personal opinion.</h1>
<div id="ticker">    
    <div class="event">test1</div>
    <div class="event">test2</div>
    <div class="event">test3</div>
    <div class="event">test4</div>
</div>​

<>CSS

.event{float: left; width: 100px;}​

Javascript/Jquery

(function($) {
        $.fn.textWidth = function(){
             var calc =  <span style="display:none">  + $(this).text() +  </span> ;
             $( body ).append(calc);
             var width = $( body ).find( span:last ).width();
             $( body ).find( span:last ).remove();
            return width;
        };

        $.fn.marquee = function(args) {
            var that = $(this);
            var textWidth = that.textWidth(),
                offset = that.width(),
                width = offset,
                css = {
                     text-indent  : that.css( text-indent ),
                     overflow  : that.css( overflow ), 
                     white-space  : that.css( white-space )
                },
                marqueeCss = {
                     text-indent  : width,
                     overflow  :  hidden ,
                     white-space  :  nowrap 
                },
                args = $.extend(true, { count: -1, speed: 1e1, leftToRight: false }, args),
                i = 0,
                stop = textWidth*-1,
                dfd = $.Deferred();

            function go() {
                if (that.data( isStopped ) != 1)
                {
                if(!that.length) return dfd.reject();
                if(width == stop) {
                    i++;
                    if(i == args.count) {
                        that.css(css);
                        return dfd.resolve();
                    }
                    if(args.leftToRight) {
                        width = textWidth*-1;
                    } else {
                        width = offset;
                    }
                }
                that.css( text-indent , width +  px );
                if(args.leftToRight) {
                    width++;
                } else {
                    width--;
                }
            }

                setTimeout(go, 10);
            };
            if(args.leftToRight) {
                width = textWidth*-1;
                width++;
                stop = offset;
            } else {
                width--;            
            }
            that.css(marqueeCss);
            that.data( isStopped , 0);
            that.bind( mouseover , function() { $(this).data( isStopped , 1); }).bind( mouseout , function() { $(this).data( isStopped , 0); });
            go();
            return dfd.promise();
        };        
    })(jQuery);
        $( h1 ).marquee();
        $( #ticker ).marquee();​
最佳回答

仅将其放在集装箱内

<div id="ticker-container">
<h1>This runs differently than the ticker for some reason. It s highly annoying in my personal opinion.</h1> <div id="ticker">    
    <div class="event">test1</div>
    <div class="event">test2</div>
    <div class="event">test3</div>
    <div class="event">test4</div>
</div>
</div>

$( #ticker-container ).marquee();
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签