If Else Statement - Jquery Animate
Bit of a JQuery beginner - trying to animate a "tab" to follow the class "开发者_运维知识库StaffPanel" as it animates outwards.
Below are my scripts. The second one works properly, animating the class outwards and attaching the .StaffTriggerActive to the button.
Problem is, I can't seem to figure out how to write a if else statement to make the button animate to the closed state once the user closes the button..
I obviously am doing something wrong - any one with ideas?
$(document).ready(function() {
$('.StaffTrigger').click(function() {
if($(this).hasClass('.StaffTriggerActive')) {
$(".StaffTriggerActive").animate ({
right: '=0'
}, "fast");
}
else {
$(".StaffTriggerActive").animate ({
right: '=340'
}, "fast");
}
});
});
$(document).ready(function(){
$(".StaffTrigger").click(function(){
$(".StaffPanel").toggle("fast");
$(this).toggleClass("StaffTriggerActive");
return false;
});
});
The hasClass
method can't have the . on the class name. Just do this way:
if ($(this).hasClass('StaffTriggerActive')) ...
精彩评论