On a little website I made- click here if you want to see it.
Anyway, using jQuery, when you scroll down, you are yanked back up, the top text changes, and one variable increases. Depending on the value of the variable, the text at the top changes accordingly. The problem here is that the number doesn't change further. It only shows the first text, which is if the variable is equal to one, but does not exceed further. Here is the code with a few notes to express what I mean.
FUN = 0; //Does not have "var" so it can be global to the following function
window.onscroll = function(ev) {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
FUN++; //Adds one to FUN variable.
if(FUN==1){ //This stuff here executes just fine.
scream.playclip(); //This also works too; don't worry.
$("#text").replaceWith( "<h1>You should not have done that.</h1><br><img src='sck1.jpg'>" );
} else if(FUN==2){ //This doesn't happen.
$("#text").replaceWith( "<h1>Last chance to close the page.</h1>" );
}
$('html, body').animate({ scrollTop: 0 }, 'fast'); //This works- this is the thing that yanks the user's screen back up.
}
};
Edit: This broke it... Thanks @Fabian.
console.log(FUN + " before ++")
FUN++;
console.log(FUN + " after ++")
var, it would still be "global" to the following function (even if not at global scope and not really global), because the function would close over it. More: How do JavaScript closures work?2was never registered forFUN. Why don't you simply useif (FUN > 1)instead?[<>]toolbar button).FUN++absolutely will incrementFUN, so if you're not seeing the effect you want, the problem is something else, not that it's not being incremented.elseblock with aconsole.logof yourFUNvariable, maybe the scroll is going to fast and you are incrementing your variable too quicly result being it does not enter the second if.