/*$("#tablescroll").tablescroll( { window: 890, step: { min: 1, max: 10 }, timer: 30, ctrl: { able: true, left: ".moveleft", right: ".moveright", faster: true }, stop: true, auto: { able: true, foward: "left" } } );*/ $.fn.tablescroll = function(data) { var $this = this,scrollmar; if ( this.outerwidth(true) <= data.window ) { return this; } this.wrap("
"); var box = this.parent(); data.step.now = data.step.min; this.find("tr").each( function() { $(this).find("td").each( function() { $(this).clone(true).insertafter( $(this).parent().find("td:last") ); } ) } ); function move() { var middle = $this.find("tr:first > td:eq(" + ( $this.find("tr:first > td").length / 2 ) + ")").offset().left; var first = $this.find("tr:first > td:first").offset().left; if ( data.auto.foward == "left" || data.auto.foward == 0 ) { if ( middle - data.step.now > box.offset().left ) { box.scrollleft( box.scrollleft() + data.step.now ); } else { box.scrollleft( math.abs(middle - box.offset().left - data.step.now) ); } } else if ( data.auto.foward == "right" || data.auto.foward == 1 ) { if ( first + data.step.now < box.offset().left ) { box.scrollleft( box.scrollleft() - data.step.now ); } else { box.scrollleft( $this.outerwidth(true) / 2 - ( data.step.now - ( box.offset().left - first ) ) ); } } } function start() { scrollmar = setinterval( function() { move(); } , data.timer ); } function end() { clearinterval(scrollmar); } if ( data.auto.able ) { start(); } if ( data.stop ) { box.hover( function() { end(); },function() { start(); } ); } if ( data.ctrl.able ) { $(data.ctrl.left).mouseover( function() { data.auto.foward = 0; } ); $(data.ctrl.right).mouseover( function() { data.auto.foward = 1; } ); $(data.ctrl.left + "," + data.ctrl.right).mousedown( function() { data.step.now = data.step.max; } ).css("cursor","pointer"); $(document).mouseup( function() { data.step.now = data.step.min; } ); } return this; };