我的网站上有一个滚动旁边bar。
www.rayshaft.comand I also have ajax pagination, so the sidebar is supposed to be floating until it reaches the footer of the page, but the problem is it works only with the 1st page, when the 2nd page is loaded via ajax the sidebar is not floating. I was suggested to change my js code so that every time after ajax page load i need to call scroll function again or i need to recalculate maxY and footTop ech time scroll happens. I don t know any js programming so could you please help me. How can I modify this code to get what I want?
$(window).load(function(){
$(function() {
var top = $( #sidebar ).offset().top - parseFloat($( #sidebar ).css( marginTop ).replace(/auto/, 0));
var footTop = $( #footer ).offset().top - parseFloat($( #footer ).css( marginTop ).replace(/auto/, 0));
var maxY = footTop - $( #sidebar ).outerHeight();
$(window).scroll(function(evt) {
var y = $(this).scrollTop();
if (y > top) {
if (y < maxY) {
$( #sidebar ).addClass( fixed ).removeAttr( style );
} else {
$( #sidebar ).removeClass( fixed ).css({
position: absolute ,
top: (maxY - top) + px
});
}
} else {
$( #sidebar ).removeClass( fixed );
}
});