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); }; }); });
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
Post a Comment