我一直試圖讓側邊欄左右滑動,具體取決於點擊。爲什麼這個jquery動畫不起作用?
我確實嘗試切換無法使其工作。
現在我已經試過這個代碼,它的作品第一次點擊的時候,但一旦點擊出於某種原因再次點擊時無法正常工作:
$('.pushbutton').on('click',function(){
$('.left_sidebar, .footer').animate({left: "-320px"}, 800);
$('.main_body_right').animate({marginLeft: "25px"}, 800);
$('.pushbutton').animate({fontSize: "24px",fontWeight: "400",paddingTop: "3px"}, 500);
$('.pushbutton').html('+');
$('.pushbutton').attr('class','pushbuttonplus');
});
$('.pushbuttonplus').on('click',function(){
$('.left_sidebar, .footer').animate({left: "0px"}, 800);
$('.main_body_right').animate({marginLeft: "325px"}, 800);
$('.pushbuttonplus').animate({fontSize: "26px",fontWeight: "700",paddingTop: "0px"}, 500);
$('.pushbuttonplus').html('-');
$('.pushbuttonplus').attr('class','pushbutton');
});
把例子:http://jsflidde.net/ – ZiTAL
每次 「.pushbutton」 被點擊時,你縫附上新的點擊事件處理程序在所有「.pushbuttonplus」。可能導致動畫和性能問題碰撞的元素 – Stphane
@ f00bar .pushbutton僅用於一次,然後類attr更改爲pushbuttonplus,因此在更改爲另一個之前,一次只能點擊一次 – Robert