Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
antony-k1208 opened this issue Jun 19, 2013 · 12 comments
Closed

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

antony-k1208 opened this issue Jun 19, 2013 · 12 comments

Comments

@antony-k1208
Copy link

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
Copy link
Author

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

@JamyGolden
Copy link

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
Copy link
Author

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
Copy link

$(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
Copy link
Author

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

@ziplizard
Copy link

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

@antony-k1208
Copy link
Author

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
Copy link

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
Copy link

alexlevn commented Mar 8, 2018

Thks, it took me 1 day.

@ivanVanelov
Copy link

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
Copy link

@ivanVanelov You saved my sanity... Thanks!

@pramacha
Copy link

@ivanVanelov Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants