Advertisement
Guest User

simple jquery tabs

a guest
Dec 29th, 2010
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.74 KB | None | 0 0
  1. <html>
  2. <head>
  3.  
  4. <style type="text/css">
  5.  
  6. body {
  7.     font-family:helvetica, arial, sans-serif;
  8.     font-size:12px;
  9.     line-height:24px;
  10. }
  11.  
  12. ul.tabs {
  13.     list-style:none;
  14.     margin:0;
  15.     padding:0;
  16. }
  17.  
  18. ul.tabs li {
  19.     float:left;
  20.     line-height:28px;
  21.     margin:0 1px 0;
  22.     background-color:#f0f0f0;
  23. }
  24.  
  25. ul.tabs li a {
  26.     display:block;
  27.     padding:0 8px;
  28.     text-decoration:none;
  29. }
  30.  
  31. ul.tabs li.active a {
  32.     cursor:default;
  33.     color:#fff;
  34. }
  35.  
  36. ul.tabs li.active {
  37.     background-color:#000;
  38. }
  39.  
  40. .tabContent {
  41.     display:none;
  42.     padding:30px;
  43.     border:1px solid #000;
  44. }
  45.  
  46. .container {
  47.     clear:both;
  48. }
  49.  
  50. </style>
  51.  
  52. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
  53. <script type="text/javascript">
  54.  
  55. $(function() {
  56.     $("ul.tabs>li>a").click(function() {
  57.         var self = $(this);
  58.         if(self.parent("li").is(".active")) return false;
  59.         $("ul.tabs>li").removeClass("active");
  60.         self.parent("li").addClass("active");
  61.         $(".tabContent").stop(true, true);
  62.         if($(".tabContent:visible, .tabContent:animated").length) {
  63.             $(".tabContent:visible, .tabContent:animated").not(self).fadeOut(300, function() {
  64.                 $(".tabcontent[rel='" + self.attr("id") + "']").fadeIn(300);
  65.             });
  66.         } else {
  67.             $(".tabcontent[rel='" + self.attr("id") + "']").fadeIn(300);
  68.         }
  69.         return false;
  70.     });
  71.     $("ul.tabs>li>a:first").trigger("click");
  72. });
  73. </script>
  74. </head>
  75. <body>
  76.  
  77. <div class="container">
  78.     <ul class="tabs">
  79.         <li><a href="#" id="tab1">tab 1</a></li>
  80.         <li><a href="#" id="tab2">tab 2</a></li>
  81.         <li><a href="#" id="tab3">tab 3</a></li>
  82.     </ul>
  83. </div>
  84.  
  85. <div class="container">
  86.     <div class="tabContent" rel="tab1"><p>"Did you see a man in the pit?" I said; but he made no answer to that.  We became silent, and stood watching for a time side by side, deriving, I fancy, a certain comfort in one another's company.  Then I shifted my position to a little knoll that gave me the advantage of a yard or more of elevation and when I looked for him presently he was walking towards Woking.</p></div>
  87.     <div class="tabContent" rel="tab2"><p>'Ah, well! It means much the same thing,' said the Duchess, digging her  sharp little chin into Alice's shoulder as she added, 'and the moral  of THAT is&mdash;"Take care of the sense, and the sounds will take care of  themselves."'</p></div>
  88.     <div class="tabContent" rel="tab3"><p>At Andover, and later at Yale, I had pitched on winning ball teams.  My speed and control must both have been above the ordinary, for I made such a record during my senior year at college that overtures were made to me in behalf of one of the great major-league teams; but in the tightest pitch that ever had confronted me in the past I had never been in such need for control as now.</p></div>
  89. </div>
  90.  
  91. </body>
  92. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement