Enma Nii
Enma Nii

Reputation: 123

fadeIn, fadeOut jQuery code snippet

$(window).bind('scroll', function() {
    if ($(this).scrollTop() > 520) {
        $('.element').fadeIn();
    } if ($(this).scrollTop() < 520) {
        $('.element').stop().fadeOut();
    }
});

I put it together like this so that the element fades in after 520 and fades out if less than 520. My question is the following: Are they brackets correct or would it be better to make it differently?

Upvotes: 0

Views: 69

Answers (1)

Alex Gray
Alex Gray

Reputation: 110

I think this is sort of off topic for this section, but check out this part of SO: Code Review

Syntax looks good but as others have said you might want to change it to else if, or an else depending on what you want.

Here is the best resource I've found on if/else statements:

MDN If. . . Else

Upvotes: 1

Related Questions