Sunday, 15 September 2013

javascript - add class making scroll with mouse and browser using jquery -



javascript - add class making scroll with mouse and browser using jquery -

hi please need help on issue, have fixed menu goes fixed when capturing coordinates, , when menu puts sticky when create scroll mouse or straight on browser, want add together class, if create click on menu want remove class, code:

$(document).on('scroll', amargin); function amargin(e) { if ($('nav').hasclass('fixed_menu')) { $('main').addclass('margin'); } else { $('main').removeclass('margin'); } e.preventdefault(); }

also im adding tag nav class calls fixed_menu, makes menu position fixed, why im using if sentence, because want add together class margin when class fixed_menu appears, , when create scroll mouse or browser, when create click on menu want remove it, maintain in mind when click on sticky menu moves capturing scrolltop , offset.top event, making animate page.

this seems cool idea, thought take shot @ it. think looking this jsfiddle.

your logic off. basic thought if have navigation bar @ top want new navigation bar appear , stick top of screen when user scrolls past bar @ top. hence need check see if user's position top of document greater height of navigation bar.

var top = $('body').scrolltop(); var navheight = $('#navbar').height(); if(top > navheight) { $('#fixedbar').fadein(); } else { $('#fixedbar').fadeout(); }

i create more dynamic there no need sec navigation bar, illustration believe approach works.

javascript jquery

No comments:

Post a Comment