banswiper.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. (function($) {
  2. $.fn.extend({
  3. "soChange": function(o) {
  4. o = $.extend({
  5. thumbObj: null,
  6. botPrev: null,
  7. botNext: null,
  8. changeType: 'fade',
  9. thumbNowClass: 'act',
  10. thumbOverEvent: true,
  11. slideTime: 1000,
  12. autoChange: true,
  13. clickFalse: true,
  14. overStop: true,
  15. changeTime: 5000,
  16. delayTime: 300
  17. }, o || {});
  18. var _self = $(this);
  19. var thumbObj;
  20. var size = _self.size();
  21. var nowIndex = 0;
  22. var index;
  23. var startRun;
  24. var delayRun;
  25. function fadeAB() {
  26. if (nowIndex != index) {
  27. if (o.thumbObj) {
  28. $(o.thumbObj).removeClass(o.thumbNowClass).eq(index).addClass(o
  29. .thumbNowClass);
  30. }
  31. if (o.slideTime <= 0) {
  32. _self.eq(nowIndex).hide();
  33. _self.eq(index).show();
  34. } else if (o.changeType == 'fade') {
  35. _self.eq(nowIndex).fadeOut(o.slideTime);
  36. _self.eq(index).fadeIn(o.slideTime);
  37. } else {
  38. _self.eq(nowIndex).slideUp(o.slideTime);
  39. _self.eq(index).slideDown(o.slideTime);
  40. }
  41. nowIndex = index;
  42. }
  43. }
  44. function runNext() {
  45. index = (nowIndex + 1) % size;
  46. fadeAB();
  47. }
  48. _self.hide().eq(0).show();
  49. if (o.thumbObj) {
  50. thumbObj = $(o.thumbObj);
  51. thumbObj.removeClass(o.thumbNowClass).eq(0).addClass(o.thumbNowClass);
  52. thumbObj.click(function() {
  53. index = thumbObj.index($(this));
  54. fadeAB();
  55. if (o.clickFalse) {
  56. return false;
  57. }
  58. });
  59. if (o.thumbOverEvent) {
  60. thumbObj.hover(function() {
  61. index = thumbObj.index($(this));
  62. delayRun = setTimeout(fadeAB, o.delayTime);
  63. }, function() {
  64. clearTimeout(delayRun);
  65. });
  66. }
  67. }
  68. if (o.botNext) {
  69. $(o.botNext).click(function() {
  70. if (_self.queue().length < 1) {
  71. runNext();
  72. }
  73. return false;
  74. });
  75. }
  76. if (o.botPrev) {
  77. $(o.botPrev).click(function() {
  78. if (_self.queue().length < 1) {
  79. index = (nowIndex + size - 1) % size;
  80. fadeAB();
  81. }
  82. return false;
  83. });
  84. }
  85. if (o.autoChange) {
  86. startRun = setInterval(runNext, o.changeTime);
  87. if (o.overStop) {
  88. _self.hover(function() {
  89. clearInterval(startRun);
  90. }, function() {
  91. startRun = setInterval(runNext, o.changeTime);
  92. });
  93. }
  94. }
  95. }
  96. })
  97. })(jQuery);