JS-判断元素在当前窗口是否可见
/**
* 判断元素是否可见
* @param {Object} elm
*/
function checkVisible(elm) {
var rect = elm.getBoundingClientRect();
//获取当前浏览器的视口高度,不包括工具栏和滚动条
//document.documentElement.clientHeight兼容 Internet Explorer 8、7、6、5
var viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
//bottom top是相对于视口的左上角位置
//bottom大于0或者top-视口高度小于0可见
return !(rect.bottom < 0 || rect.top - viewHeight >= 0);
}