Skip to content

CSS scrolltop return 0

ythy edited this page Jan 19, 2018 · 1 revision

use pageYOffset instead of scrolltop

pageYOffset

The pageXOffset and pageYOffset properties returns the pixels the current document has been scrolled from the upper left corner of the window, horizontally and vertically.

The pageXOffset and pageYOffset properties are equal to the scrollX and scrollY properties.

These properties are read-only.

Note

For IE8 and earlier, you can use document.documentElement.scrollLeft and document.documentElement.scrollTop instead

conclusion

pageYOffset 支持IE9及以上. 尽量不用scrolltop已保持chrome兼容性

Clone this wiki locally