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