1. 程式人生 > 其它 >監聽滾動條 獲取指定元素到可視區域頂部的距離

監聽滾動條 獲取指定元素到可視區域頂部的距離

技術標籤:js

// 監聽滾動條 獲取指定元素到可視區域頂部的距離
$(window).scroll(function(){
 var box=document.getElementById('scroll');
  console.log(box.getBoundingClientRect().top)
})