vendredi 30 décembre 2016

.animate() in jQuery and if condition seems to don't work

I'm not an expert in jQuery and I try to create a kind of button-toggle : When I click on the switch-button "Home/News", the content should switch too.

But that seems to don't work... Despite the if condition, the condition AND the else are executed... I don't get it. Someone can tell me where do I failed ?

Here is the jsfiddle : http://ift.tt/2iNQ8Hu

The jQuery :

$(document).ready(function(){ function switchButton(){ console.log("coucou") $('.onoffswitch').click(function(){ if($('.onoffswitch').hasClass('nothere')){ $('.container_slide_actu').animate({ left : 0}, 700); $('.onoffswitch').removeClass('nothere'); }else{ $('.container_slide_actu').animate({ left : '-100%'}, 700); $('.onoffswitch').addClass('nothere'); } }); } switchButton(); });

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire