João Rafael
João Rafael

Reputation: 413

Change background on scroll

How can i make the background-color change when scrolling, not based on the distance from top specifically, but based on the div background? I don't know if you understand, but here is an example of what i want like this site here: http://readymag.com/.

Upvotes: 1

Views: 1684

Answers (2)

VVV
VVV

Reputation: 7603

You could use a plugin like Waypoint which allows you to trigger a function depending where you are scrolling.

In your case, you could trigger a function that would change the background color.

Upvotes: 1

Dipesh Parmar
Dipesh Parmar

Reputation: 27382

$(document).scroll(function()
{
    $('body').css('background-color','#9966'+($(this).scrollTop()/10))
});

OR

$(window).scroll(function () { 
    $('body').css('background-color','#9966'+($(this).scrollTop()/10));
});

Upvotes: 3

Related Questions