1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- (function($){
- $.fn.textSlider = function(options){
-
- var defaults = {
- speed:40,
- line:1
- };
- var opts = $.extend({}, defaults, options);
- var $timer;
- function marquee(obj, _speed){
- var top = 0;
- var margintop;
- $timer = setInterval(function(){
- top++;
- margintop = 0-top;
- obj.find("ul").animate({
- marginTop: margintop
- },0,function(){
- var s = Math.abs(parseInt($(this).css("margin-top")));
- if(s >=obj.find("li").height()){
- top = 0;
- $(this).css("margin-top", 0);
- $(this).find("li").slice(0, 1).appendTo($(this));
- }
- });
- }, _speed);
- }
- this.each(function(){
- var speed = opts["speed"],line = opts["line"],_this = $(this);
- var $ul =_this.find("ul");
- if($ul.height() > _this.height()){
- marquee(_this, speed);
- }
-
- _this.on('touchstart', function(ev){
-
- clearInterval($timer);
- });
-
- _this.on('swipeup', function(ev){
-
- clearInterval($timer);
- if($ul.height() > _this.height()){
- for(i=0;i<opts.line;i++){
- $ul.find("li").first().appendTo($ul);
- }
- $ul.css("margin-top",0);
- }
- });
-
- _this.on('swipedown', function(ev){
-
- clearInterval($timer);
- if($ul.height() > _this.height()){
- for(i=0;i<opts.line;i++){
- $ul.find("li").first().before($ul.find("li").last());
- }
- $ul.css("margin-top",0);
- }
- });
-
- _this.on('touchend',function(ev){
-
- if($ul.height() > _this.height()){
- marquee(_this, speed);
- }
- });
- });
- }
- })(Zepto);
|