[DikeJS]RequireJS引入CSS样式文件(五)_html/css_WEB-ITnose

PHP中文网
Release: 2016-06-21 09:08:46
Original
1736 people have browsed it

在实际开发组件时,我们常常需要关注组件的样式,样式如何定义,以及样式如何引用,我关注此问题时也纠结了一小下,不过还好,RequireJS周边给我们提供了丰富的插件,我们可以直接使用css.js,具体的使用方法如下:

(function () {
    requirejs.config({
        paths: {
            jquery   : 'lib/jquery-1.11.1.min',
            Template : 'Component/util/Template',
            Button   : 'Component/view/button/Button',
            Canvas   : 'Component/view/canvas/Canvas',
            Container: 'Component/view/container/Container'
        },
        /**
         * 设置css.js文件路径
         */
        map  : {
            '*': {
                'css' : 'lib/css'
            }
        },
        /**
         * 样式按照需要加载加载 键值名和加载模块的名称一致,目的是加载模块时加载对应的css样式
         */
        shim : {
            'Canvas1': ['css!./Component/view/canvas/css/login.css'],
            'Button' : ['css!./Component/view/button/css/ty-main.css']
        }
    });

    define(function (require) {
        var $ = require('jquery');
        $(document).ready(function () {
            var container = new (require('Container'))({
                id    : 'container',
                name  : 'container',
                width : '300px',
                height: '500px',
                render: $('body')
            });

            var canvas = new (require('Canvas'))({
                id       : 'Canvas',
                name     : 'Canvas',
                //render   : $('body'),
                listeners: {
                    onReady: function (_this) {
                        var ctx = _this.getContext2D();
                        ctx.fillStyle = '#FF0000';
                        ctx.fillRect(0, 0, 80, 100);
                    },
                    click  : function () {
                        alert(1);
                    }
                }
            });

             container.add(canvas);

        });
    });
})();
Copy after login

请仔细查看注释,你就明白如何引入css样式了,而且是在初次加载页面的时候就会将css样式写入到

以上就是[DikeJS]RequireJS引入CSS样式文件(五)_html/css_WEB-ITnose的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template