简体   繁体   English

如何在动态表格中附加CSS值

[英]How do I append CSS values in a dynamic table

I'm using GWT table which is being generate dynamically with lots of columns but with out horizontal scroll bar and to get the scrollbar, we need wrapper with fixed width around the table, but GWT do create container but not adding any width to it. 我正在使用GWT表,该表是动态生成的,具有许多列,但是没有水平滚动条,并且要获取滚动条,我们需要在表周围具有固定宽度的包装器,但是GWT确实会创建容器,但不向其添加任何宽度。

To solve the problem, I'm calculating width of screen and adding it to the table wrapper, which is adding scroll bar to the table but working weirdly. 为了解决该问题,我正在计算屏幕的宽度并将其添加到表包装器中,这是在表中添加滚动条,但工作异常。

  1. It adds scroll bar when I move mouse near to table 当我将鼠标移到桌子附近时,它会添加滚动条
  2. It doesn't work when in resize the table 调整表格大小时不起作用

I'm using Live() as it works for run time objects, also I can't use click event. 我正在使用Live()因为它适用于运行时对象,也不能使用click事件。

Here is the code: 这是代码:

$(function() {
    var screenwidth = $(window).width();
    $('body').live("mouseover", function() {
        $('.scrollbar').css({
            'width' : (screenwidth) - 40
        });
        $("body").unbind("mouseover");
    });
});
  1. Use $('body').on("mouseover") If you are getting scrollbar you can handle that by setting up overflow to none. 使用$('body')。on(“ mouseover”)如果获得滚动条,可以通过将overflow设置为none来处理。 If you need to change css dynamically you can add / remove class and keep css separate from your code. 如果需要动态更改CSS,则可以添加/删除类,并使CSS与代码分开。 Its a good practice. 这是一个好习惯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM