Find the “potential” width of a hidden element

前端 未结 10 1314
慢半拍i
慢半拍i 2020-12-03 09:31

I\'m currently extending the lavalamp plugin to work on dropdown menus but I\'ve encountered a small problem. I need to know the offsetWidth of an element that

10条回答
  •  有刺的猬
    2020-12-03 10:08

    What I did was ; by the time hiding that element, stored its width in its dataset. It only will work for you if you can hide programmatically.

    ie.

    When Hiding ;

    var elem = $("selectorOfElement");
    
    elem.dataset.orgWidth = elem.clientWidth;
    

    Later when getting ;

    var elem = $("selectorOfElement");
    
    var originalWidthWas = elem.dataset.orgWidth;
    

提交回复
热议问题