jquery - scrollTop() if/else switchClass() animation for shrinking nav bar -


i use jquery ui method switchclass() because want have control on animation duration. 1 thing confused identifying classes in switchclass() methods. use '.' before 1 class not other? below code. is, it's not working. there more elegant solution this?

 $(document).ready(function(){     $(window).on("scroll touchmove", function () {         var x = $(document).scrolltop();         if( x > 0 ) {          $('.header').switchclass('header', '.header.tiny', 500);          $('.logo').switchclass('logo', '.logo.tiny', 500);         } else {          $('.logo.tiny').switchclass('tiny', '.logo', 500);          $('.header.tiny').switchclass('tiny', '.header', 500);        };       });     }); 

https://jqueryui.com/switchclass/

you dont need '.' see:

 $(document).ready(function(){ $(window).on("scroll touchmove", function () {     var x = $(document).scrolltop();     if( x > 0 ) {      $('div.header').switchclass('header', 'tiny', 500);      $('div.logo').switchclass('logo', 'tiny', 500);     } else {      $('div.logo div.tiny').switchclass('tiny', 'logo', 500);      $('div.header div.tiny').switchclass('tiny', 'header', 500);    };   }); }); 

and try define classes objects e.g: div.header


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -