var offset = $(selector).offset();
The values of offset variable changes if we scroll the page up and down, i want the exact and fixed offset value
One other potential cause is if your happens to have CSS that sets overflow-x: hidden; - that completely breaks jQuery's offset() method.
overflow-x: hidden;
offset()
In that case, $(window).scrollTop() is always 0, so the accepted answer does not work.
$(window).scrollTop()