我一直试图让侧边栏左右滑动,具体取决于点击。为什么这个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