less.js lazy sheet load

前端 未结 6 1163
天涯浪人
天涯浪人 2021-02-06 00:07

I\'m wondering if there is a way to load a single less sheet sometime after a page load. This question has an answer that explains how to reload all the sheets, but for my use-

6条回答
  •  旧时难觅i
    2021-02-06 00:38

    Just adopted MatthewForr answer for my own needs:

    $.each(['/css/style1.less', '/css/style2.less'], function (index, fileName) {
        var $sheet = $('', {
            href: fileName,
            rel: 'stylesheet/less',
            type: 'text/css'
        }).appendTo('head');
        less.sheets.push($sheet[0]);
    });
    less.refresh();
    

提交回复
热议问题