It's really hard to catch an exact size. Look for the size, and anything larger - for example, if win1
is 100, it'll fire at 100-199, then for win2
if it's at 200-299, and so on.
Note I also check the window sizes largest to smallest (you can do them smallest to largest, then just be sure to change >
to <
and add an extra check for sizes larger than win3
.
Also, make your checks if ... else if ... else
statemnts so you don't accidentally fire it multiple times (win3 is larger than win2, so win2 would fire even at win3).
function parallaxScroll(){
var scrolledX = $(window).scrollLeft();
var windowsize = $(window).width();
var win0 = 0;
var win1 = windowsize;
var win2 = windowsize * 2;
var win3 = windowsize * 2;
if (scrolledX >= win3) {
$("#test").text("mark3");
}
else if (scrolledX >= win2) {
$("#test").text("mark2");
}
else {
$("#test").text("mark1");
}
}