获取视口宽高
<script>
let clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
let clientHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
</script>
获取滚动距离
<script>
var scrollTop=window.pageYOffset || document.documentElement.scrollTop
</script>
获取鼠标位置
<script>
function getMouse(event){
//相对于浏览器窗口的距离(不包含滚动的距离)
var mouseLeft = event.clientX
var mouseTop = event.clientY
//相对于文档的距离
var mouseLeft = event.pageX
var mouseTop = event.pageY
}
</script>
获取元素位置(相对于浏览器窗口,会随着滚动而改变)
<script>
var a = document.querySelector('.a')
var aa = a.getBoundingClientRect()
aa.top //元素上边框相对于窗口的上边高度
aa.left //元素左边框相对于窗口的左边的距离
</script>