jQuery .show() a flex box

前端 未结 9 1281
南笙
南笙 2021-02-06 20:56

I have an element with a flexbox

    div#myFlexbox{ display:flex; }

after hide it and show it, it gets messed up.<

9条回答
  •  一整个雨季
    2021-02-06 21:32

    The idea is to create a custom function showFlex() similar to jQuery show() and call it with the element which need to have the display:flex; property.

    jQuery Solution

    $.fn.showFlex = function() {
      this.css('display','flex');
    }
    

    $('#myFlexbox').showFlex();

    JavaScript Solution

    Object.prototype.showFlex = function() {
        this.style.display = 'flex';
    }
    

    document.getElementById('myFlexbox').showFlex();

    Hope this helps.

提交回复
热议问题