javascript - jquery animation not working right after the second click -


so trying slide down header when click on wrapper , when click again slides up. it's working when click first time, keeps sliding down again header.

here code:

var header = $("header"); $("wrapper").on("click", function () {     if (header.css({"top" : "-8%"})) {         header.animate({"top" : "0%"}, 500);     } else if (header.css("top") == '0%') {         header.animate({"top" : "-8%"}, 500);     }; }); 

try :

$(".wrapper").click( function () {     if ( $(".header").css( 'top' ) == '-8%' )         $(".header").animate( {'top' : '0%'}, 500);     else         $(".header").animate( {'top' : '-8%'}, 500); } ); 

i've supposed 'wrapper' , 'header' classes that's why i've added $(".header"). if you've tagged them, write $("#header").

sorry english, i'm french.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -