调整窗口大小时表格滚动条消失

发布于 2024-12-05 10:14:31 字数 1933 浏览 4 评论 0原文

我为电子商务网站的后台制作了一张桌子。表格内容 (tbody) 具有固定高度,并且可以通过右侧的滚动条滚动,如下图所示:http://img690.imageshack.us/img690/6483/screenshot20110917at819.png

问题是,如果我调整浏览器窗口的大小,此表格滚动条就会消失: http://img26.imageshack.us/img26/4919/screenshot20110917at820.png

我知道这应该是正常行为,但我的客户坚持保留表格滚动条,即使在调整大小时也是如此窗户。有没有办法实现这种行为?

这是供参考的css:(表体的类是scrollContent)

/* define height and width of scrollable area. Add 16px to width for scrollbar */
div.tableContainer {
    clear: both;
    overflow: auto;
    width: 100%; 
}

/* set table header to a fixed position. WinIE 6.x only                                           */
/* In WinIE 6.x, any element with a position property set to relative and is a child of           */ 
/* an element that has an overflow property set, the relative value translates into fixed.    */
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to     auto */
thead.fixedHeader tr {
    position: relative
}

/* set THEAD element to have block level attributes. All other non-IE browsers                */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
html>body thead.fixedHeader tr {
    display: block;
    width: 100%
}

/* define the table content to be scrollable                                                  */
/* set TBODY element to have block level attributes. All other non-IE browsers            */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
/* induced side effect is that child TDs no longer accept width: auto                     */
html>body tbody.scrollContent {
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
}

I made a table for the back-office of an e-commerce site. The table content (tbody) has a fixed height and it is scrollable through a scrollbar on the right-hand side as depicted in this picture: http://img690.imageshack.us/img690/6483/screenshot20110917at819.png

The problem is that if I resize the browser window, this table scrollbar diseappears: http://img26.imageshack.us/img26/4919/screenshot20110917at820.png

I know this is supposed to be normal behavior, but my customer insists to keep the table scrollbar even when resizing the window. Is there a way to implement this behavior?

Here is the css for reference: (the table body's class is scrollContent)

/* define height and width of scrollable area. Add 16px to width for scrollbar */
div.tableContainer {
    clear: both;
    overflow: auto;
    width: 100%; 
}

/* set table header to a fixed position. WinIE 6.x only                                           */
/* In WinIE 6.x, any element with a position property set to relative and is a child of           */ 
/* an element that has an overflow property set, the relative value translates into fixed.    */
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to     auto */
thead.fixedHeader tr {
    position: relative
}

/* set THEAD element to have block level attributes. All other non-IE browsers                */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
html>body thead.fixedHeader tr {
    display: block;
    width: 100%
}

/* define the table content to be scrollable                                                  */
/* set TBODY element to have block level attributes. All other non-IE browsers            */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
/* induced side effect is that child TDs no longer accept width: auto                     */
html>body tbody.scrollContent {
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吾性傲以野 2024-12-12 10:14:31

实际上,如果更改overflow-x:scroll或auto应该可以解决问题。由于它是隐藏的,他们无法访问滚动条,这可能是他们的抱怨。

另一种选择是运行 JavaScript 或 jquery,检查屏幕分辨率,然后用不同的表格替换表格或用较小的图像替换图像。这将允许表格缩小大小,以便它可以显示在非最大化窗口中。

/---- 编辑 ----/

检查窗口调整大小(您也不必在窗口上执行此操作,您可以在元素上执行此操作,但窗口将使您更准确地了解它们是否调整了其大小窗户。

var timerID = 0,
var winWidth = $(window).width(),
var winHeight = $(window).height();

$(document).ready(function()
{
    $(window).resize(function()
    {
        var winNewWidth = $(window).width(),
            winNewHeight = $(window).height();
        if(winWidth != winNewWidth || winHeight != winNewHeight)
        {
            window.clearTimeout(timerID);
            timerID = window.setTimeout(function()
            {
                // do something here
            },100)
        }
        winWidth = winNewWidth;
        winHeight = winNewHeight
    });
});

Actually you if you change the overflow-x: scroll or auto should resolve the problem. Since it's hidden they can't access the scroll bar which is probably their complaint.

The other option would be to run a javascript or jquery that would check for screen resolution and then replace the table with a different table or replace the images with smaller images. This would allow the table to resize down so that it could display in the non-maximized window.

/---- EDIT ----/

Check window resize (you also don't have to do this on the window you can do it on an element but the window will give you a more accurate read on whether they have resized their window.

var timerID = 0,
var winWidth = $(window).width(),
var winHeight = $(window).height();

$(document).ready(function()
{
    $(window).resize(function()
    {
        var winNewWidth = $(window).width(),
            winNewHeight = $(window).height();
        if(winWidth != winNewWidth || winHeight != winNewHeight)
        {
            window.clearTimeout(timerID);
            timerID = window.setTimeout(function()
            {
                // do something here
            },100)
        }
        winWidth = winNewWidth;
        winHeight = winNewHeight
    });
});
合约呢 2024-12-12 10:14:31

将 CSS 的溢出行为更改为始终显示,如下所示:

html>body tbody.scrollContent {
    display: block;
    overflow-y: scroll; //this will make sure to always display the scrollbar, whether it's active (available for scrolling) or not.
    overflow-x: hidden;
    width: 100%;
}

Change the oversflow behavior from CSS to always display, like so:

html>body tbody.scrollContent {
    display: block;
    overflow-y: scroll; //this will make sure to always display the scrollbar, whether it's active (available for scrolling) or not.
    overflow-x: hidden;
    width: 100%;
}
治碍 2024-12-12 10:14:31

最终的代码如下,供稍后访问此页面的人参考:

var winWidth = $(window).width();
var winHeight = $(window).height();
var winWidthDiff = 0;
var winHeightDiff = 0;
$i('scrollContent').style.maxWidth= ((winWidth-16)+"px");
$(window).resize(function(){
        var winNewWidth = $(window).width();
        var winNewHeight = $(window).height();
        winWidthDiff = winNewWidth - winWidth;
        winHeightDiff = winNewHeight - winHeight;
        winWidth = winNewWidth;
        winHeight = winNewHeight;
        scrollWidth = scrollWidth + winWidthDiff;
        scrollHeight = scrollHeight + winHeightDiff;
        $i('scrollContent').style.maxWidth= ((winWidth-16)+"px");
});

For reference to those who will visit this page later, here is the final code:

var winWidth = $(window).width();
var winHeight = $(window).height();
var winWidthDiff = 0;
var winHeightDiff = 0;
$i('scrollContent').style.maxWidth= ((winWidth-16)+"px");
$(window).resize(function(){
        var winNewWidth = $(window).width();
        var winNewHeight = $(window).height();
        winWidthDiff = winNewWidth - winWidth;
        winHeightDiff = winNewHeight - winHeight;
        winWidth = winNewWidth;
        winHeight = winNewHeight;
        scrollWidth = scrollWidth + winWidthDiff;
        scrollHeight = scrollHeight + winHeightDiff;
        $i('scrollContent').style.maxWidth= ((winWidth-16)+"px");
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文