滚动DIV元素时,请防止全页滚动



我想在DIV元素中滚动时防止页面滚动到上一页。现在,我正在使用Alvarotrigo的全页滚动,不确定这是否相关。基本上,此页面中有2个"页面"。" .table响应"在第二页上,我将其设置为"溢出:滚动"。在该Div中滚动时,它也将滚动到第一页。

我已经尝试过,但这不起作用:

$('.table-responsive').on( 'mousewheel DOMMouseScroll', function (e) { 
var e0 = e.originalEvent;
var delta = e0.wheelDelta || -e0.detail;
this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
e.preventDefault();  
});

html:

<div class="table-responsive">
   <div class="table">
      <thead>TABLE</thead>
      <tbody>...</tbody>
   </div>
</div>

CSS:

.table-responsive {
width: 70%;
text-align: left;
margin-top: 30px;
margin-bottom: 30px;
margin-left: auto;
margin-right: auto;
height: 40vh;
overflow: scroll;
border: 3px solid #fff;
background-color: rgba(0,0,0,0.6); 
}
$('.table-responsive').on('mouseover', function(){
  $('body').css('overflow', 'hidden');
}).on('mouseout', function(){
  $('body').css('overflow', 'auto');
});

认为这是您要寻找的

.table-responsive {
max-width: 70%;
}
or
.table-responsive {
max-width: 250px;
}

最新更新