Wednesday, 15 April 2015

javascript - Trouble keeping a div stuck to top bar with JQuery -



javascript - Trouble keeping a div stuck to top bar with JQuery -

i'm working on wordpress blog implementing custom theme. implement functionality keeps navigation bar stuck top of screen after scroll past it. i've done research, , i've learned crucial work within jquery scripts.js file in order avoid messing theme's functionality. i'm having problem getting jquery script work. code have found research listed below, i'm not getting event trigger when looking @ error console in firefox.

the div trying stick named: #omc-main-navigation div using measure against (for when nav bar reaches top of viewport) is: #omc-over-480

$(document).ready.(function movescroller($) { var move = function() { var st = $(window).scrolltop(); var ot = $("#omc-over-480").offset().top; var s = $("#omc-main-navigation"); if(st > ot) { s.css({ position: "fixed", top: "0px" }); } else { if(st <= ot) { s.css({ position: "relative", top: "" }); } } }; $(window).scroll(move); move(); })(jquery);

javascript jquery css html

No comments:

Post a Comment