Няма описание

ScrollDiv.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. (function($) {
  2. function Scroll(obj, opt) {
  3. this.obj = obj;
  4. this.opt = $.extend(obj, opt);
  5. this.init = function() {
  6. clearInterval(obj.attr("timerID"));
  7. this.Scrolls(obj, opt);
  8. }
  9. }
  10. Scroll.prototype = {
  11. // timerID:null,
  12. Scrolls: function(obj, opt) {
  13. this.hovered(obj, opt)
  14. },
  15. scrollDown: function(obj, opt) {
  16. var _this = obj.eq(0).find("table:first");
  17. var lineH = _this.find("tr:first").height(); //获取行高
  18. _this.animate({
  19. marginTop: -lineH + "px"
  20. }, //动画展示css样式
  21. opt.speed,
  22. function() {
  23. _this.find("tr:first").appendTo(_this);
  24. _this.css({
  25. marginTop: "0px"
  26. });
  27. }
  28. )
  29. },
  30. hovered: function(obj, opt) {
  31. var timerID, $thats = this,
  32. _thisH = obj.eq(0).find("table:first").height(),
  33. thisH = obj.eq(0).height();
  34. obj.eq(0).find("table:first").unbind();
  35. //鼠标事件绑定
  36. obj.eq(0).find("table:first").hover(function() {
  37. clearInterval(obj.attr("timerID"));
  38. }, function() {
  39. if(_thisH > thisH) {
  40. timerID = setInterval(function() {
  41. $thats.scrollDown(obj, opt)
  42. }, opt.timer); //这里调用向下或者向上滚动函数
  43. obj.attr("timerID", timerID);
  44. }
  45. }).mouseout();
  46. }
  47. }
  48. $.fn.Scroll = function(obj) {
  49. var $that = this;
  50. //参数初始化
  51. if(!obj) var obj = {};
  52. var _this = $that.eq(0).find("table:first");
  53. var lineH = _this.find("tr:first").height(), //获取行高
  54. line = obj.line ? parseInt(obj.line, 10) : parseInt($that.height() / lineH, 10), //每次滚动的行数,默认为一屏,即父容器高度
  55. speed = obj.speed ? parseInt(obj.speed, 10) : 500, //卷动速度,数值越大,速度越慢(毫秒)
  56. timer = obj.timer ? parseInt(obj.timer, 10) : 2000; //滚动的时间间隔(毫秒)
  57. if(line == 0) line = 1;
  58. var rollNumObj = new Scroll($that, obj);
  59. rollNumObj.init();
  60. };
  61. })(jQuery);