fontscroll.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. +-------------------------------------------------------------------
  3. * jQuery FontScroll - ���������Ϲ������ - http://java2.sinaapp.com
  4. +-------------------------------------------------------------------
  5. * @version 1.0.0 beta
  6. * @since 2014.06.12
  7. * @author kongzhim <kongzhim@163.com> <http://java2.sinaapp.com>
  8. * @github http://git.oschina.net/kzm/FontScroll
  9. +-------------------------------------------------------------------
  10. */
  11. /*大屏*/
  12. /*(function($){
  13. $.fn.FontScroll = function(options){
  14. var d = {time: 2000,s: 'fontColor',num: 1};
  15. var o = $.extend(d,options);
  16. this.children('ul').addClass('line');
  17. var _con = $('.line').eq(0);
  18. var _conH = _con.height(); //�����ܸ߶�
  19. var _conChildH = _con.children().eq(0).height();//һ�ι����߶�
  20. var _temp = _conChildH; //��ʱ����
  21. var _time = d.time; //�������
  22. var _s = d.s; //�������
  23. _con.clone().insertAfter(_con);//��ʼ����¡
  24. //��ʽ����
  25. var num = d.num;
  26. var _p = this.find('li');
  27. var allNum = _p.length;
  28. _p.eq(num).addClass(_s);
  29. var timeID = setInterval(Up,_time);
  30. console.log(timeID);
  31. this.hover(function(){clearInterval(timeID)},function(){timeID = setInterval(Up,_time);});
  32. function Up(){
  33. _con.animate({marginTop: '-'+_conChildH});
  34. //��ʽ����
  35. _p.removeClass(_s);
  36. num += 1;
  37. _p.eq(num).addClass(_s);
  38. if(_conH == _conChildH){
  39. _con.animate({marginTop: '-'+_conChildH},"normal",over);
  40. } else {
  41. _conChildH += _temp;
  42. }
  43. }
  44. function over(){
  45. _con.attr("style",'margin-top:0');
  46. _conChildH = _temp;
  47. num = 1;
  48. _p.removeClass(_s);
  49. _p.eq(num).addClass(_s);
  50. }
  51. }
  52. })(jQuery);*/
  53. // JavaScript Document
  54. (function($){
  55. $.fn.myScroll = function(options){
  56. //默认配置
  57. var defaults = {
  58. speed:60, //滚动速度,值越大速度越慢
  59. rowHeight:24 //每行的高度
  60. };
  61. var opts = $.extend({}, defaults, options),intId = [];
  62. function marquee(obj, step){
  63. obj.find("ul").animate({
  64. marginTop: '-=1'
  65. },0,function(){
  66. var s = Math.abs(parseInt($(this).css("margin-top")));
  67. if(s >= step){
  68. $(this).find("li").slice(0, 1).appendTo($(this));
  69. $(this).css("margin-top", 0);
  70. }
  71. });
  72. }
  73. this.each(function(i){
  74. var sh = opts["rowHeight"],speed = opts["speed"],_this = $(this);
  75. intId[i] = setInterval(function(){
  76. if(_this.find("ul").height()<=_this.height()){
  77. clearInterval(intId[i]);
  78. }else{
  79. marquee(_this, sh);
  80. }
  81. }, speed);
  82. _this.hover(function(){
  83. clearInterval(intId[i]);
  84. },function(){
  85. intId[i] = setInterval(function(){
  86. if(_this.find("ul").height()<=_this.height()){
  87. clearInterval(intId[i]);
  88. }else{
  89. marquee(_this, sh);
  90. }
  91. }, speed);
  92. });
  93. });
  94. }
  95. })(jQuery);