简体   繁体   English

div滚动无限循环

[英]infinite loop for div scroll

I am trying to impliment tweet scroller on http://www.hubspot.com/ 我试图在http://www.hubspot.com/上隐含推文滚动条

在此处输入图片说明

which is i guess using tweet-scroller from http://code.divshot.com/tweetscroller/ 我猜这是使用http://code.divshot.com/tweetscroller/中的 tweet-scroller

but this link is broken as demo is not working. 但是此链接已断开,因为演示无法正常工作。

i looked for alternative. 我寻找替代品。

I found http://jsfiddle.net/doktormolle/4c5tt/ 我发现http://jsfiddle.net/doktormolle/4c5tt/

HTML: HTML:

<ul class="slide">
  <li><img src="http://www.google.com/logos/2010/canadianthanksgiving2010-hp.jpg"/></li>
  <li><img src="http://www.google.com/logos/2010/germany10-hp.gif"/></li>
  <li><img src="http://www.google.com/logos/stpatricks_02.gif"/></li>
</ul>

CSS: CSS:

 ul.slide{margin:0;
      padding:0;
      height:80px;
      list-style-type:none;}
 ul.slide li{float:left;
         list-style-type:none;}
 ul.slide img{border:1px solid silver;
         height:80px;}

JS: JS:

 //Plugin start
(function ($) {
    var methods = {
     init: function (options) {
         return this.each(function () {
             var _this = $(this);
             _this.data('marquee', options);
             var _li = $('>li', _this);

             _this.wrap('<div class="slide_container"></div>')
                 .height(_this.height())
                 .hover(function () {
                         if ($(this).data('marquee').stop) {
                             $(this).stop(true, false);
                         }
                     },
                     function () {
                         if ($(this).data('marquee').stop) {
                             $(this).marquee('slide');
                         }
                     })
                 .parent()
                 .css({
                     position: 'relative',
                     overflow: 'hidden',
                     'height': $('>li', _this).height()
                 })
                 .find('>ul')
                 .css({
                     width: screen.width * 2,
                     position: 'absolute'
                 });

             for (var i = 0; i < Math.ceil((screen.width * 3) / _this.width()); ++i) {
                 _this.append(_li.clone());
             }

             _this.marquee('slide');
         });
     },

     slide: function () {
         var $this = this;
         $this.animate({
                 'left': $('>li', $this).width() * -1
             },
             $this.data('marquee').duration,
             'swing',
             function () {
                 $this.css('left', 0).append($('>li:first', $this));
                 $this.delay($this.data('marquee').delay).marquee('slide');

             }
         );

     }
     };

     $.fn.marquee = function (m) {
     var settings = {
         'delay': 2000,
         'duration': 900,
         'stop': true
     };

     if (typeof m === 'object' || !m) {
         if (m) {
             $.extend(settings, m);
         }

         return methods.init.apply(this, [settings]);
     } else {
         return methods[m].apply(this);
     }
 };
 })(jQuery);

 //Plugin end

 //call
 $(document).ready(
 function () {
     $('.slide').marquee({
         delay: 3000
     });
 }
 );

which works fine with little modification i did 我做了一点修改就可以正常工作

http://jsfiddle.net/3pZwR/1/ http://jsfiddle.net/3pZwR/1/

only problem is it stops after each div is scrolled. 唯一的问题是它会在每个div滚动后停止。

I want it to be infinite scroll like effect without getting it stopped. 我希望它具有无限滚动效果,而不会停止。 like on hubspot. 就像在枢纽上一样。

You should use another JQuery Easing method instead of "swing". 您应该使用另一个JQuery Easing方法而不是“ swing”。 Have a look at the Easings on the JQuery website: http://api.jqueryui.com/easings/ 在JQuery网站上查看Easings: http ://api.jqueryui.com/easings/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM