0

I have a <div class="header"> which I want to be able to animate after the page has been scrolled 300px. I tried using the following script:

$(body).scroll( function() {
var value = $(this).scrollTop();
if ( value > 300 )
    $(".header").css("height", "220px");
else
    $(".header").css("height", "120px");
});

But nothing seems to be working...

The <div class="header"> is a fixed element at the top of the page, and I wonder if I can add more than one css argument, unlike $("div").css("one css-argument", "value")? (This has been solved)

Edit: I want the header to adjust it's height and font size when the page has been scrolled more than 300px.

2

1 Answer 1

3

$(body) is wrong unless body is a variable defined somewhere else.

What you actually should to use though is $(document)

Updated

$(document).scroll(function () {
    var value = $(this).scrollTop();
    if (value > 300) $(".header").css({height:220, fontSize:40});
    else $(".header").css({height:120, fontSize:20});
});

FIDDLE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.