File tree Expand file tree Collapse file tree 3 files changed +32
-4
lines changed
Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -58,3 +58,19 @@ searchBar.addEventListener('keyup', (e) => {
5858 }
5959 } ) ;
6060} ) ;
61+
62+ // tabbed content
63+ const tabs = document . querySelector ( '.tabs' ) ;
64+ const panels = document . querySelectorAll ( '.panel' ) ;
65+ tabs . addEventListener ( 'click' , ( e ) => {
66+ if ( e . target . tagName == 'LI' ) {
67+ const targetPanel = document . querySelector ( e . target . dataset . target ) ;
68+ Array . from ( panels ) . forEach ( ( panel ) => {
69+ if ( panel == targetPanel ) {
70+ panel . classList . add ( 'active' ) ;
71+ } else {
72+ panel . classList . remove ( 'active' ) ;
73+ }
74+ } ) ;
75+ }
76+ } ) ;
Original file line number Diff line number Diff line change @@ -43,6 +43,20 @@ <h2 class="title">Books to Read</h2>
4343 < input type ="text " placeholder ="Add a book... " />
4444 < button > Add</ button >
4545 </ form >
46+ < div id ="tabbed-content ">
47+ < ul class ="tabs ">
48+ < li data-target ="#about " class ="active "> About</ li >
49+ < li data-target ="#contact "> Contact</ li >
50+ </ ul >
51+ < div class ="panel active " id ="about ">
52+ < p > Content for about tab...</ p >
53+ < p > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum id nunc porta urna ornare rhoncus. Ut convallis ante at.</ p >
54+ </ div >
55+ < div class ="panel " id ="contact ">
56+ < p > Content for contact tab...</ p >
57+ < p > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum id nunc porta urna ornare rhoncus. Ut convallis ante at.</ p >
58+ </ div >
59+ </ div >
4660 </ div >
4761 < script src ="app.js "> </ script >
4862 </ body >
Original file line number Diff line number Diff line change @@ -124,7 +124,6 @@ h1, h2{
124124 line-height : 52px ;
125125}
126126
127- /*
128127# tabbed-content li {
129128 display : inline-block;
130129 padding : 10px 14px ;
@@ -134,14 +133,13 @@ h1, h2{
134133 margin-right : 10px ;
135134}
136135
137- #tabbed-content .tab {
136+ # tabbed-content .panel {
138137 display : none;
139138 border : 1px solid # ddd ;
140139 padding : 0 10px ;
141140 border-radius : 4px ;
142141}
143142
144- #tabbed-content .tab .active{
143+ # tabbed-content .panel .active {
145144 display : block;
146145}
147- */
You can’t perform that action at this time.
0 commit comments