admin管理员组文章数量:1334821
I have searched high and low for an answer for this question and I FINALLY found it. I am writing this to hopefully save a future programmer a lot of time and frustration.
Please ment below if you would like to see something added or have any questions and I will add it. This will bee a more plete answer as people bring forth issues.
I have searched high and low for an answer for this question and I FINALLY found it. I am writing this to hopefully save a future programmer a lot of time and frustration.
Please ment below if you would like to see something added or have any questions and I will add it. This will bee a more plete answer as people bring forth issues.
Share Improve this question edited Apr 17, 2015 at 19:58 Noah Gary asked Apr 17, 2015 at 19:49 Noah GaryNoah Gary 96012 silver badges26 bronze badges 5- 6 if you really think that this can help anyone and for this reason you have wrote it, then you should paste the solution as an answer,, not in question – A.B Commented Apr 17, 2015 at 19:51
- 1 Your heart is in the right place :) - it's only your solution that is not... – LcSalazar Commented Apr 17, 2015 at 19:53
- 1 Furthermore , you will need to mark it accepted in order to get the (answered) effect... – A.B Commented Apr 17, 2015 at 19:56
- I have moved the solution to the answer section. Thanks. I cannot accept my own answer for two days so... until then. – Noah Gary Commented Apr 17, 2015 at 19:56
- please vote me back up if I have corrected the problem you down voted me for. – Noah Gary Commented Sep 25, 2015 at 21:24
1 Answer
Reset to default 9This is a solution to find/detect the scroll bar position on the three major browsers(IE, Chrome, Firefox). Let me know if you find a version of these browsers that will not work and I will edit this answer to include that info.
Older versions of chrome:
var scrollTop = document.body.scrollTop; //Chrome
var scrollLeft = document.body.scrollLeft; //Chrome
Chrome > v.78.0.3904.97 (That I know of)
var scrollTop = window.scrollY; //Chrome
var scrollLeft = window.scrollX; //Chrome
Other Browsers:
var otherScrollTop = document.documentElement.scrollTop; //IE & Firefox
var otherScrollLeft = document.documentElement.scrollLeft; //IE & Firefox
These variables will detect the scroll position for the whole page.
As @Eloy Pineda Mentioned: You can write this more concisely with:
var scrollTop = window.scrollY || document.body.scrollTop || document.documentElement.scrollTop;
var scrollLeft = window.scrollX || document.body.scrollLeft || document.documentElement.scrollLeft;
本文标签: javascriptCrossbrowser Detecting scroll position JS onlyStack Overflow
版权声明:本文标题:javascript - Cross-browser: Detecting scroll position JS only - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742382268a2464329.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论