1

私はこれを私のhtmlに持っています:

<script type="text/javascript">
    less = {
        env: "development", // or "production"
        async: false,       // load imports async
        fileAsync: false,   // load imports async when in a page under
                            // a file protocol
        poll: 1000,         // when in watch mode, time in ms between polls
        functions: {
            returnCenter: function (value, context) {
                return 'center';
            }
        },      // user functions, keyed by name
        dumpLineNumbers: "comments", // or "mediaQuery" or "all"
        relativeUrls: false,// whether to adjust url's to be relative
                            // if false, url's are already relative to the
                            // entry less file
        rootpath: ":/a.com/"// a path to add on to the start of every url
                            //resource
    };
</script>
<script src="less.js" type="text/javascript"></script>

関数では、less ファイルで関数を作成して使用するにはどうすればよいでしょうか?

ありがとう、そして幸運を!

PD この returnCenter は機能しません。パラメータありまたはパラメータなし。

4

1 に答える 1

0

何らかの理由で、関数名を小文字で書く必要があります。また、関数は適切な型を返す必要があります。

試す:

<script>
less = { 
    env: "development",
    functions: { 
        returncenter: function(context, value) {
            return new(less.tree.Anonymous)('center');
        }
    }
};
</script>

次の Less コードを使用できるようになりました。

selector {
property: returncenter();    
}

上記の Less コードは、次の CSS コードにコンパイルされます。

selector {
property: center;    
}

NB も参照してください: LessCSS を使用したユーザー定義関数?

于 2014-10-06T20:34:56.873 に答える