元問答欄目視頻美女
  1. 編程問答
  2. 答案列表

JavaScript 檢測元素是否在螢幕中

回答列表
檢查元素是否在窗口中最好的方法是使用intersectionobserver
const callback = (entries) =>{
entries.foreach((entry) =>{
if (entry.isintersecting) {
// `entry.target` is the dom element
console.log(`${entry.target.id} is visible`);
}
});
};
const options = {
threshold:1.0。
};
const observer = new intersectionobserver(callback,options);
const btn = document.getelementbyid("btn");
const bottombtn = document.getelementbyid("bottom-btn");
observer.observe(btn);
observer.observe(bottombtn);
猜你喜歡
相關推薦