scroll_ul.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. (function ($) {
  2. $.fn.myScroll = function (options) {
  3. //默认配置
  4. var defaults = {
  5. speed: 40, //滚动速度,值越大速度越慢
  6. rowHeight: 24 //每行的高度
  7. };
  8. var opts = $.extend({}, defaults, options),
  9. 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"],
  23. speed = opts["speed"],
  24. _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);