Skip to content

Instantly share code, notes, and snippets.

@morrxy
Last active November 9, 2017 06:15
Show Gist options
  • Save morrxy/6b8fb062fcb8ff2d49dc8625c9232e06 to your computer and use it in GitHub Desktop.
Save morrxy/6b8fb062fcb8ff2d49dc8625c9232e06 to your computer and use it in GitHub Desktop.
[window scroll] #javascript

use jquery

var scrollTop = $(window).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(window).height();

if ((scrollTop + windowHeight) == scrollHeight) {
    console.log('scroll to bottom')
}

native js

窗口宽高 https://stackoverflow.com/a/8876069

var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);

上滚高度 https://stackoverflow.com/a/14384091, pageYOffset是scrollY的别名

var top  = window.pageYOffset || document.documentElement.scrollTop,
left = window.pageXOffset || document.documentElement.scrollLeft;    

文档高度 https://stackoverflow.com/a/5484623

var height = document.body.clientHeight;
var width = document.body.clientWidth;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment