Can anyone help me pinpoint the issue with my script please?
$(function () {
var top = $(\'#sidebar\').offset().top - parseFloat($(\'#sidebar\').css(\'marginTop\
The problem is that you are forgetting the margin-top
of your sidebar in your calculation:
var maxY = footTop - $('#sidebar').outerHeight() - 68;
In your Prototype JSFiddle the sidebar just happened to have no margin-top
.
On a sidenote: you may want to cache your selectors to improve performance. If you use the same selector more than once, for example $("#sidebar")
, put it in a variable:var sidebar = $("#sidebar");
.