Know what overflow:hidden has hidden

后端 未结 4 1152
长情又很酷
长情又很酷 2020-12-13 16:31

I want to know if there is any way you can call and use what the overflow:hidden has well hidden.

To clarify what I mean, in this example I would like t

4条回答
  •  情书的邮戳
    2020-12-13 16:58

    Try this solution using jQuery

    JQuery

    $t = $('#text');
    
    var shown, all, hiddenWidth;
    
    // we start with the shown width set (via css) at 100px
    shown = $t.width();
    
    // we change the css to overflow:visible, float:left, and width:auto
    $t.css({'overflow': 'visible', 'float': 'left', 'width': 'auto'});
    
    // and get the total width of the text
    all = $t.width();
    
    // then we set the css back to the way it was
    $t.css({'overflow': 'hidden', 'float': '', 'width': '100px'});
    
    // and retrieve the hiddenWidth
    hiddenWidth = all - shown;
    

    HTML

    This is shown. This is hidden

    CSS

    #text{
        outline:1px solid orange;
        width:100px;
        height:20px;
        overflow:hidden;
    }
    

提交回复
热议问题