because your code is here
$(document).scroll(function(){
so your scroll functionwork if you scroll documentor body, but since you are using position: fixed, there is not scrollbarin body, but scrollbaris to continue to
<div id="right">
...
</div>
scroll function ,
$(document).scroll(function(){
...
});
$("#right").scroll(function(){
...
});