Reputation: 13
I'm building a wordpress theme and I'm developing a sidebar which stays fixed during scrolling and goes up when you reach the comments. Here's a part of my jQuery code:
jQuery(window).bind('scroll', function () {
var flag = '';
if (calcTop() === true && calcBottom() === false && flag !== 'false')
{
jQuery('#aside-sidebar').css({'position': 'fixed', "top": "59px"});
}
else if (calcTop() === false && calcBottom() === false && flag !== 'false')
{
jQuery('#aside-sidebar').css({'position': 'absolute', "top": ""});
}
else
{
flag = 'false';
jQuery('#aside-sidebar').css({'position': 'absolute', "top": sidebarPosition()+"px"});
console.log(flag);
}
});
The issue I have is that the flag
variable is not changing according to the last part of the if statement. Any hint?
Upvotes: 0
Views: 100
Reputation: 721
in the else part if you are setting flag to 'false' it will definitely be set as u expected.
In your condition part i think you can add some refactoring as in if and else if part you are having two similar conditions .
and why are you setting flag to a string variable instead you can easily use boolean flag here.
last but not the least you can watch the console for any error. if any error occurs that means it is not coming to the setter part flag = 'false';
Upvotes: 1