RoadFlow2.1 临时演示

roadui.accordion.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //滑动菜单
  2. ; RoadUI.Accordion = function ()
  3. {
  4. var instance = this;
  5. this.init = function ($divs, showIndex)
  6. {
  7. $divs.each(function ()
  8. {
  9. var $accordionTitles = $(".accordiontitle", $(this));
  10. var borderHeight = $(this).css("border").indexOf("none") >= 0 ? -1 : 0;//div是否有边框,没有边框内容高度要-1
  11. var contentHeight = $(this).height() - ($accordionTitles.size() * 27) + ($accordionTitles.size() - 1) + 2 + borderHeight;
  12. var defaultShowIndex = showIndex || 0;
  13. $accordionTitles.each(function (i)
  14. {
  15. if (i == 0)
  16. {
  17. $(this).css({ "border-top": "none" });
  18. }
  19. else
  20. {
  21. $(this).css({ "border-bottom": "none" });
  22. }
  23. $(this).next().css({ "height": contentHeight.toString() + "px", "display": i == defaultShowIndex ? "block" : "none" });
  24. $(this).bind("click", function ()
  25. {
  26. var border = "";
  27. $(".accordion div .accordiontitle").each(function ()
  28. {
  29. $(this).next().hide();
  30. $(this).css({ "border-bottom": "none" });
  31. if (border.length == 0 && $(this).css("border").indexOf("none") == 0)
  32. {
  33. border = $(this).css("border");
  34. }
  35. });
  36. $(this).next().show(300);
  37. $(this).css({ "border-bottom": border });
  38. });
  39. });
  40. });
  41. };
  42. this.resize = function ($div)
  43. {
  44. var $accordionTitles = $("div .accordiontitle", $div);
  45. var borderHeight = $div.css("border").indexOf("none") >= 0 ? -1 : 0;//div是否有边框,没有边框内容高度要-1
  46. var contentHeight = $div.height() - ($accordionTitles.size() * 27) + ($accordionTitles.size() - 1) + 2 + borderHeight;
  47. $(".accordioncontent", $div).height(contentHeight);
  48. }
  49. }