jquery-rocktabs.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. rocktabs 选择卡
  3. caratename:chenxihu
  4. caratetime:214-04-06 21:40:00
  5. email:qqqq2900@126.com
  6. homepage:www.xh829.com
  7. <div class="tabs" tabsindex="0">
  8. <div class="tabstitle">
  9. <ul>
  10. <li index="1" class="li01">公告</li>
  11. <li index="2">聚品茶</li>
  12. <li index="3">促销信息</li>
  13. </ul>
  14. </div>
  15. <div class="tabscont hborder" style="height:259px; border-top:none">
  16. <div index="1">
  17. </div>
  18. <div index="2">
  19. </div>
  20. <div index="3">
  21. </div>
  22. </div>
  23. </div>
  24. */
  25. (function ($) {
  26. function rocktabs(element, options){
  27. var obj = element;
  28. var can = options;
  29. var rand = ''+parseInt(Math.random()*99999)+'';
  30. var me = this;
  31. this.rand = rand;
  32. var titobj,contobj;
  33. //初始化
  34. this.init = function(){
  35. titobj = obj.find("div[class^='tabstitle']").find('li[index]');
  36. contobj = obj.find("div[class^='tabscont']").find('div[index]');
  37. var tri = obj.attr('trigger');
  38. if(tri == null || !tri)tri='click';
  39. titobj[tri](function(){
  40. me.clicktitle(this);
  41. });
  42. var ind = obj.attr('tabsindex');//选中第几个选择卡
  43. if(ind == null || !ind)ind='0';
  44. if(ind == 'last')ind = titobj.length-1;
  45. this.indexshow(parseInt(ind));
  46. };
  47. this.clicktitle = function(o1){
  48. var o = $(o1);
  49. var oi = o.attr('index');
  50. this.indexshow(parseInt(oi));
  51. };
  52. this.indexshow = function(oi){
  53. titobj.removeClass();
  54. $(titobj[oi]).addClass('li01');
  55. contobj.hide();
  56. $(contobj[oi]).show();
  57. };
  58. }
  59. $.fn.rocktabs = function(options){
  60. var defaultVal = {
  61. trigger:'click'
  62. };
  63. var can = $.extend({}, defaultVal, options);
  64. return this.each(function() {
  65. var clsa = new rocktabs($(this), can);
  66. clsa.init();
  67. return clsa;
  68. });
  69. };
  70. })(jQuery);