2013-11-29 25 views
0

這裏是我的 JsFiddle獲得一個小三角形上垂直標籤效應

$(document).ready(function() { 
$('.content #tab1, .content #tab2, .content #tab3, .content #tab4').css('display','none'); 
$('.vertical-tab').click(function() { 
    custom_reset(); 
    $(this).css('background-color','#fff'); 
    var currentId = $(this).attr('id'); 
    $('.content').find("#" + currentId).css('display','block'); 
}); 
}); 
function custom_reset() { 
$('.vertical-tab').css('background-color','#abcdef'); 
$('.content #tab1, .content #tab2, .content #tab3, .content #tab4').css('display','none'); 
} 

在點擊選項卡上,我想一個小左三角形出現在標籤的中心被點擊。我如何得到這種效果。

+0

形式'tab'你的意思是藍色點擊'li'(S) – UDB

+0

@UDB是的,我的意思是可點擊的li(s) – shubendrak

+0

你可以使用三角形字符而不是圖像,如果你想要▼▼▲▲▲ – jasonscript

回答

1

CSS

//display the div as a triangle 
border-bottom: 10px solid transparent; 
border-top: 10px solid transparent; 
border-left: 20px solid #abcdef; 
height: 0px; 
width: 0px; 

檢查我的更新小提琴http://jsfiddle.net/rynhe/HADnu/12/

JS

$(document).ready(function() { 
    $('.content #tab1, .content #tab2, .content #tab3, .content #tab4').css('display','none'); 
    $('.vertical-tab').click(function() { 
     $(".arrow").remove(); /*remove arrow div from a*/ 
     custom_reset(); 
     $(this).css('background-color','#fff'); 
     var currentId = $(this).attr('id'); 
     var aData = "<div class='arrow'></div>"; 
     $(this).append(aData); /*add arrow div to the current a*/ 
     $('.content').find("#" + currentId).css('display','block'); 
    }); 
}); 
function custom_reset() { 
$('.vertical-tab').css('background-color','#abcdef'); 
    $('.content #tab1, .content #tab2, .content #tab3, .content #tab4').css('display','none'); 
} 

CSS

ul { 
    list-style-type: none; 
    height: 408px; 
    float: left; 
    margin: 0; 
    padding: 0; 
} 
li { 

} 
ul a { 
    width: 20px; 
    height: 100px; 
    background: #abcdef; 
    display: block; 
    border: 1px solid #000; 
    position:relative; /*Added relative for place the div inside a*/ 
} 

div.arrow { 
    border-bottom: 10px solid transparent; 
    border-top: 10px solid transparent; 
    border-left: 20px solid #abcdef; 
    height: 0; 
    width: 0px; 
    position:absolute; 
    top:40px; 
    right:0px; 
} 
0
<li> 
    <a href="#" class="vertical-tab" id="tab1"></a> 
    <img id="triangle" src="/path"/> 
</li> 

#triangle{ 
    position: absolute; 
    display:none; 
    z-index:1000; 
    margin-top:-60px //as per the position you want to place the image at 
} 

$('.vertical-tab').click(function() { 

    //your code as it is.. 

    var currentId = $(this).attr('id'); 

    $(this).siblings('#triangle').show() //add this statement 

    //your code as it is.. 

}); 

/*add #triangle in function custom_reset*/ 

$('#triangle,.content #tab1, .content #tab2, .content #tab3, .content #tab4').css('display','none'); 

DEMO