試圖在bootstraps accordion組件上設置panel-title的margin-left屬性。我試過使用.toggle(),但它只是做一些奇怪的錯誤。我嘗試了幾種不同的方法,但似乎沒有任何工作。你可以檢查出來這裏codepenanimate bootstrap accordion panel-title on click jquery
//Method Onee By Adding A Class
$('.panel-title').click(function() {
$(this).addClass('open-panel')
})
$('.panel-title').click(function() {
$(this).removeClass('open-panel')
})
//Method Two By Click but just animates open and closes right after another
$('.panel-title').click(function(){
$(this).animate({"margin-left": '+=20'});
}),
$('.panel-title').click(function(){
$(this).animate({"margin-left": '-=20'});
});
//Method Three the panels shrink among themselves cause of toggle()
$(".panel-title").toggle(
function() {
$(this).animate({"margin-left": "+50px"});
},
function() {
$(this).animate({"margin-left": "0px"});
});
什麼是錯的方法嗎? –