bootstrap responsive table content wrapping

前端 未结 10 1730
南旧
南旧 2020-12-24 11:10

I have HTML similar to this:

    
10条回答
  •  一生所求
    2020-12-24 11:34

    Add your new class "tableresp" with table-responisve class and then add below code in your js file

    $(".tableresp").on('click', '.dropdown-toggle', function(event) {
    
        if ($('.dropdown-menu').length) {
            var elm = $('.dropdown-menu'),
                docHeight = $(document).height(),
                docWidth = $(document).width(),
                btn_offset = $(this).offset(),
                btn_width = $(this).outerWidth(),
                btn_height = $(this).outerHeight(),
                elm_width = elm.outerWidth(),
                elm_height = elm.outerHeight(),
                table_offset = $(".tableresp").offset(),
                table_width = $(".tableresp").width(),
                table_height = $(".tableresp").height(),
    
                tableoffright = table_width + table_offset.left,
                tableoffbottom = table_height + table_offset.top,
                rem_tablewidth = docWidth - tableoffright,
                rem_tableheight = docHeight - tableoffbottom,
                elm_offsetleft = btn_offset.left,
                elm_offsetright = btn_offset.left + btn_width,
                elm_offsettop = btn_offset.top + btn_height,
                btn_offsetbottom = elm_offsettop,
    
                left_edge = (elm_offsetleft - table_offset.left) < elm_width,
                top_edge = btn_offset.top < elm_height,
                right_edge = (table_width - elm_offsetleft) < elm_width,
                bottom_edge = (tableoffbottom - btn_offsetbottom) < elm_height;
    
            console.log(tableoffbottom);
            console.log(btn_offsetbottom);
            console.log(bottom_edge);
            console.log((tableoffbottom - btn_offsetbottom) + "|| " + elm_height);
    
    
            var table_offset_bottom = docHeight - (table_offset.top + table_height);
    
            var touchTableBottom = (btn_offset.top + btn_height + (elm_height * 2)) - table_offset.top;
    
            var bottomedge = touchTableBottom > table_offset_bottom;
    
            if (left_edge) {
                $(this).addClass('left-edge');
            } else {
                $('.dropdown-menu').removeClass('left-edge');
            }
            if (bottom_edge) {
                $(this).parent().addClass('dropup');
            } else {
                $(this).parent().removeClass('dropup');
            }
    
        }
    });
    var table_smallheight = $('.tableresp'),
        positioning = table_smallheight.parent();
    
    if (table_smallheight.height() < 320) {
        positioning.addClass('positioning');
        $('.tableresp .dropdown,.tableresp .adropup').css('position', 'static');
    
    } else {
        positioning.removeClass('positioning');
        $('.tableresp .dropdown,.tableresp .dropup').css('position', 'relative');
    
    }
    

提交回复
热议问题