jQuery Append CSS File and Wait until Loaded?

前端 未结 2 1398
醉梦人生
醉梦人生 2021-01-05 07:47

I am trying to append a css file using

$(\'head\').append(\'\');

That wo

2条回答
  •  花落未央
    2021-01-05 07:55

    Just check when one of the rules of the new CSS has been applied:

    $('head').append('');
    
    var fakeListener = setInterval(function(){
        if($("body").css("text-align")=== "center"){
            clearInterval(fakeListener)
            // What you want to do after it loads
        }
    },50)
    

    (That is a working example)

提交回复
热议问题