代码之家  ›  专栏  ›  技术社区  ›  crimson589

调整窗口大小时的数据表垂直页面拟合

  •  0
  • crimson589  · 技术社区  · 8 年前

    跟随数据表上的垂直页面调整博客 https://datatables.net/blog/2015-04-10 ,我正试图以相同的方式设置表,但使用窗口大小调整事件。这就是我要做的,

    <script>
         var prevHeight = 0; //for storing the previous height of the window
         $(document).ready(function() {
                prevHeight = $(window).height(); //get the current height of the window on load
         });
    
         $(window).on('resize', function(e){
             var currentHeight = $(window).height(); //height of the window after resize
             var wrapper = $('.resize_wrapper'); //div containing the table
             var resizeStartHeight = wrapper.height(); //height of the wrapper
    
             var height = resizeStartHeight + (currentHeight - prevHeight); //new height for the wrapper
             if ( height < 180 ) { //setting a minimum height
                 height = 180;
             }
             wrapper.height( height ); //set the new height for the wrapper
             prevHeight = $(window).height(); //store the new height of the window
         });
    
    </script>
    

    表容器正在调整大小,我的表页长度正在更改。到目前为止,这段代码仍然有效,但我似乎无法找出我遗漏了什么,因为在我的表下还有一个很大的空白区域。下面没有其他东西,我的table/div是页面上的最后一个元素。

    pageResize result

    0 回复  |  直到 8 年前
    推荐文章