Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  172] [ 1]  / answers: 1 / hits: 28747  / 12 Years ago, fri, april 27, 2012, 12:00:00

I'm trying to animate a boxShadow on the scroll event of my #container div. Everything works except I can't figure out a good way to detect the scrollbar reaching the top so that the boxShadows can animate out. This is my code so far



   $('#container').scroll(
function()
{
$('#white').animate(
{
boxShadow: 0 8px 8px -7px #696868
},
fast);
if ($('#container').scrollTop() == 0)
{
$('#white').animate(
{
boxShadow: 0 0 0 0 #696868
},
fast);
}
}
);


I've added a demo. The initial on scroll animate works perfectly, but when the bar returns to top their is a rather long delay before the second animation kicks in. http://jsfiddle.net/JYqC3/14/


More From » jquery

 Answers
33

Hope this helps



Used .scrollTop



$('#my_div').scroll(function() {
var pos = $('#my_div').scrollTop();
if (pos == 0) {
alert('top of the div');
}
});


DEMO



EDIT: better animation added to demo


[#85938] Thursday, April 26, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emiliano

Total Points: 381
Total Questions: 109
Total Answers: 93

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
emiliano questions
;