j-accordin.min.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. (function($) {
  2. $.fn.jaccordion = function() {
  3. $(this).each(function() {
  4. var c = $(this).children().length;
  5. var d = Array(c - 1);
  6. var e = Array(c - 1);
  7. $(this).children().each(function(a) {
  8. if (a == (c - 1)) return;
  9. e[a] = $(this).position().top;
  10. d[a] = $(this).position().top - $(this).children().outerHeight()
  11. });
  12. var f = this;
  13. $(this).children().mouseenter(function() {
  14. var a = $(f).children().index(this);
  15. var b = $(f).children().index($(f).children('[class~="current"]'));
  16. if (!$(this).hasClass('current')) {
  17. if (b > a) {
  18. for (var i = b - 1; i >= a; i--) {
  19. $($(f).children().get(i)).stop(false, false);
  20. to_top = e[i] + 'px';
  21. $($(f).children().get(i)).animate({
  22. top: to_top
  23. })
  24. }
  25. } else if (b < a) {
  26. for (var i = b; i < a; i++) {
  27. $($(f).children().get(i)).stop(false, false);
  28. to_top = d[i] + 'px';
  29. $($(f).children().get(i)).animate({
  30. top: to_top
  31. })
  32. }
  33. }
  34. $(f).children().removeClass('current');
  35. $(this).addClass('current')
  36. }
  37. })
  38. })
  39. }
  40. })(jQuery);