jquery - "Picking up" header on Y position javascript -


i want toggle navbar's position style property between fixed , relative based on y scroll position.

here's example: http://www.granapstudio.com/

here's javascript. tried switching classes

$(function() {    var header = $(".clearheader");    $(window).scroll(function() {      var scroll = $(window).scrolltop();      if (scroll >= 800) {        header.removeclass('clearheader').addclass("darkheader");      }      else {        header.removeclass("darkheader").addclass('clearheader');      }    });  }); 

the problem: solution doesn't work when zoom in or zoom out.

it seems example page provided using jquery plugin

https://github.com/garand/sticky