scroll.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // JavaScript Document
  2. (function($){
  3. $.fn.myScroll = function(options){
  4. //默认配置
  5. var defaults = {
  6. speed:40, //滚动速度,值越大速度越慢
  7. rowHeight:24 //每行的高度
  8. };
  9. var opts = $.extend({}, defaults, options),intId = [];
  10. function marquee(obj, step){
  11. obj.find("ul").animate({
  12. marginTop: '-=1'
  13. },0,function(){
  14. var s = Math.abs(parseInt($(this).css("margin-top")));
  15. if(s >= step){
  16. $(this).find("li").slice(0, 1).appendTo($(this));
  17. $(this).css("margin-top", 0);
  18. }
  19. });
  20. }
  21. this.each(function(i){
  22. var sh = opts["rowHeight"],speed = opts["speed"],_this = $(this);
  23. intId[i] = setInterval(function(){
  24. if(_this.find("ul").height()<=_this.height()){
  25. clearInterval(intId[i]);
  26. }else{
  27. marquee(_this, sh);
  28. }
  29. }, speed);
  30. _this.hover(function(){
  31. clearInterval(intId[i]);
  32. },function(){
  33. intId[i] = setInterval(function(){
  34. if(_this.find("ul").height()<=_this.height()){
  35. clearInterval(intId[i]);
  36. }else{
  37. marquee(_this, sh);
  38. }
  39. }, speed);
  40. });
  41. });
  42. }
  43. })(jQuery);