scroll.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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: '-=40'
  13. },1000,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. $(this).css('opacity','100');
  20. console.log(32);
  21. });
  22. }
  23. this.each(function(i){
  24. var sh = opts["rowHeight"],speed = opts["speed"],_this = $(this);
  25. intId[i] = setInterval(function(){
  26. if(_this.find("ul").height()<=_this.height()){
  27. clearInterval(intId[i]);
  28. }else{
  29. marquee(_this, sh);
  30. }
  31. }, speed);
  32. _this.hover(function(){
  33. clearInterval(intId[i]);
  34. },function(){
  35. intId[i] = setInterval(function(){
  36. if(_this.find("ul").height()<=_this.height()){
  37. clearInterval(intId[i]);
  38. }else{
  39. marquee(_this, sh);
  40. }
  41. }, speed);
  42. });
  43. });
  44. }
  45. })(jQuery);