隐藏

OutSystems中使用js滚动事件获取某元素滚动位置

发布:2024/12/8 23:23:17作者:管理员 来源:本站 浏览次数:98

var _is=false;

window.addEventListener('scroll', function(e) {

   var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;

 console.log(scrollTop);

var offsetHeight = document.getElementById("reactContainer").offsetHeight;

 scrollTop = window.pageYOffset;

 console.log(offsetHeight,scrollTop);

 scrollTop=document.querySelector('.screen-container').scrollTop;

   offsetHeight=document.querySelector('.screen-container').offsetHeight;

   console.log(offsetHeight,scrollTop);

   var rect =document.querySelector('.title-top-table').getBoundingClientRect();

   console.log('.title-top-table .table .table-header -----',rect.top);

   rect =document.querySelector('.table-header').getBoundingClientRect();

   console.log('第一个表头 -----',rect.top);

   var ee= document.querySelector('.table-header');

   if(rect.top<-60 && _is!=true){

      _is=true;

      ee.style.position='fixed';

      ee.style.Top='60px';

   }


var ee2= document.querySelectorAll('.table-header')[1];

var rect2 =ee2.getBoundingClientRect();

console.log('第二个表头 -----',rect2.top);

   if(rect2.top==100 && _is==true){

      _is=false;

      ee.style.position='unset';

      //ee.style.Top='60px';

   }


   /*

   if(rect.top>50){

       ee.style.position='unset';

       _is=false;

   }

*/



},true);


window.addEventListener('resize', function(event) {   console.log('变了');}, true);