Reputation: 181
$(document).scroll(function() {
var distanceLeft = $(document).scrollLeft();
if( distanceLeft > 3800)
{
$('#first_circle').animate({
opacity: 1
}, 1000);
}
if( distanceLeft < 3800)
{
$('#first_circle').animate({
opacity: 0
}, 1000);
}
)};
Hi Im trying to correct this so that when the scroll goes past 3800 the div fades in and when the user scrolls back it fades out? thank you for any input
Upvotes: 0
Views: 665
Reputation: 33408
You can of course use a simple way like mkey answer. However if you need a more complex thing to "animate" try jQuery Transe. It is a thorough solution for exactly this problem. You can change almost anything based on the current scroll offset (even CSS3-Transforms and suchlike).
In your case, try something like this:
$('#fading').transe({
direction: 'x',
start: 3575,
end: 4150,
css: 'opacity',
from: 0,
to: 1
});
Upvotes: 0
Reputation: 212
Just change the vars and add some math: http://jsfiddle.net/z7E9u/155/
Upvotes: 2