Got a variable that should have a value assigned to it based on window width. Width conditional statement works (checked with console.log). Adding class works as well if variable is declared and assigned a value outside the conditional statement. But nothing works if variable is inside that if statement. What am i missing?
if ($(window).width() < 960) {
var stickywidth = 200;
} else {
var stickywidth = 500;
}
$(window).scroll(function() {
if ($(this).scrollTop() === stickywidth) {
$('.sticky').addClass('opensticky');
}
});