탭메뉴 jquery

HTML (Markup)

<ul class="tabs">
    <li class="active"><span><a href="#tab1">메뉴1</a></span></li>
    <li><span><a href="#tab2">메뉴2</a></span></li>
    <li><span><a href="#tab3">메뉴3</a></span></li>
    <li><span><a href="#tab4">메뉴4</a></span></li>
</ul>

<div class="tab_container">
    <div class="tab_content" id="tab1">1</div>
    <div class="tab_content" id="tab2">2</div>
    <div class="tab_content" id="tab3">3</div>
    <div class="tab_content" id="tab4">4</div>
</div>

JavaScript

$(document).ready(function(){
    //Default Action
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content
    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
    });
});
탭메뉴 jquery 탭메뉴 jquery Reviewed by jieun on 오전 9:32 Rating: 5

댓글 없음:

Powered by Blogger.