CSS-Tricks / MovingBoxes

Simple horizontal slider which grows up the current box when it's in focus (image, title & text) and back down when it's not in focus.
http://css-tricks.github.io/MovingBoxes/
GNU Lesser General Public License v3.0
280 stars 147 forks source link

(window).scroll / ("body").scroll isnt working in chrome/safari #120

Closed antony-k1208 closed 11 years ago

antony-k1208 commented 11 years ago

I wanna add a scroll to top button to my website, but the event binding of (window).scroll{()}; doesnt seem to work. So ive changed it to $("body").scroll(function() {}); which works in every browser, only chrome/safari arent working. To which element i can bind the scroll event, to solve my problem?

antony-k1208 commented 11 years ago

$('html, body').scrollTop(), $(document).scrollTop() and $(window).scrollTop() return always 0...

JamyGolden commented 11 years ago

http://api.jquery.com/scrollTop/ - $('html').scrollTop() and $('body').scrollTop() should return 0.

This should scroll to the top of the page

$('html, body').animate({
    scrollTop: 0
});
antony-k1208 commented 11 years ago

No it shouldnt return 0. Otherwise how can u implement a scroll to top image which should only displayed if the user is scrolling the page to a certain amount? Check the values in FF i.e. and see the result.

Anyway your solution isnt working for me in chrome. Other suggestions?

JamyGolden commented 11 years ago
$(window).scrollTop()

I think that should do what you're looking for.

As for the animate, it should work in all browsers: http://jsfiddle.net/m4TJt/

antony-k1208 commented 11 years ago

Yeah thanks. I found the mistake, it was because of a wrong body,html css rule...

ziplizard commented 10 years ago

Do you recall the wrong body,html CSS rule? I think I'm having the same problem and cannot track it down.

antony-k1208 commented 10 years ago

sorry for the delay.

I think it was something like that I had a full inline div (in size of the body) and got in trouble with inner / outer divs.

AnilKumarSahoo commented 10 years ago

Thanks a lot.......Superb.

After spent 2 days I got the solution because of this code. It's Simple but useful. This is working in every browser as well, So once again thanks...........

alexlevn commented 6 years ago

Thks, it took me 1 day.

ivanVanelov commented 6 years ago

Just to share some curious info. I had the same problem and apparently if the body has height: 100% set from the css the method will always return zero

otinanaipali commented 5 years ago

@ivanVanelov You saved my sanity... Thanks!

pramacha commented 5 years ago

@ivanVanelov Thank you so much!