一個小更新關於kdureidy anwser: - 它不「切換」的狀態,如果你再次點擊 - 它並不需要的「盒子」的數量考慮
下面是一個改進版本:
$('body').on('click', '.box', function(e) {
var $target = $(this)
, targetIsActive = $target.hasClass('active')
, $boxes = $('.box')
, boxesCount = $boxes.length
, inactiveWidth = 100/boxesCount
, activeWidth = inactiveWidth * 2
, othersActiveWith = (100 - activeWidth)/(boxesCount - 1)
;
if(!targetIsActive) {
$boxes.removeClass('active').css('width', othersActiveWith + '%');
$target.addClass('active').css('width', activeWidth + '%');
} else {
$boxes.removeClass('active').css('width', inactiveWidth + '%');
}
});
https://jsfiddle.net/xw1e34yy/
請添加您已使用的代碼 – 2017-02-19 09:16:30
@gerdi我試過這樣的:$('#quick> div.quicklink')。click(function(){ \t $(this).animate({width:「40 %)},「slow」)。siblings()。animate({'width':'15%'},「slow」); }); –