jquery - Why is this panel not working? -
have @ code here, see i'm doing bit of practice jquery , trying build tab panel.
i got stuck on trying sections move out of way once clicked on new section.
i have no idea why not working me this.
<html> <head> <script src="https://code.jquery.com/jquery-2.1.4.js"></script> <meta charset="utf-8"> <title>js bin</title> </head> <body> <div class="buttons"> <a href="" class="active_button" data-sectionid="section1">section 1</a> <a href="" data-sectionid="section2">section 2</a> <a href="" data-sectionid="section3">section 3</a> <a href="" data-sectionid="section4">section 4</a> </div> <div class="sections"> <div class="section active_section" id="section1"> section 1 <br> section 1 <br> section 1 <br> section 1 <br><br> </div> <div class="section" id="section2"> section 2 <br> section 2 <br> section 2 <br> section 2 <br> <br> </div> <div class="section" id="section3"> section 3 <br> section 3 <br> section 3 <br> section 3 <br><br> </div> <div class="section" id="section4"> section 4 <br> section 4 <br> section 4 <br> section 4 <br><br> </div> </div> </body> </html>
sass
body text-align: center padding-top: 50px color: white text-decoration: none padding: 10px background-color: grey margin: 0px -1px border-radius: 10px 10px 0px 0px transition: 0.3s ease-in-out &:hover background-color: lightgrey .active_button background-color: lightgrey .sections position: relative .section display: none padding: 20px background-color: lightgrey position: absolute width: 286px top: 10px left: 50% margin-left: -163px border-radius: 0 0 10px 10px .active_section display: block
jquery
$(function() { // capture click of section button $("a").click(function(e) { // prevent default link behaviour e.preventdefault(); // hide current active section $(".section .active_section").slideup(500, function(){ // take away active class $(this).removeclass("active_section"); }); }); // click function closes here // find out section button pressed var sectionid = $("a").attr("data-sectionid"); // slide down section $("#"+sectionid).slidedown(500, function(){ // add active class $(this).addclass("active_section"); }); });
move code click function, , it's work ;)
https://jsfiddle.net/pgytuq6j/
// capture click of section button $("a").click(function(e) { // prevent default link behaviour e.preventdefault(); // find out section button pressed var sectionid = $(this).attr("data-sectionid"); // hide current active section $(".active_section").slideup(500, function(){ // take away active class $(this).removeclass("active_section"); }); // slide down section $("#"+sectionid).slidedown(500, function(){ // add active class $(this).addclass("active_section"); }); }); // click function closes here
this want ?
Comments
Post a Comment