【问题标题】:enyo framework to integrate which raphaelenyo 框架要集成哪个 raphael
【发布时间】:2015-08-27 15:23:06
【问题描述】:

我正在尝试将 Raphael 与 enyo.js 集成以使用 Raphael 而不是通过 enyo 创建 SVG 组件,因此我可以使用一些 Raphael 功能。我想用它的子组件svg替换默认呈现的div,我在jsfiddle下面创建。谁能帮我修一下?

http://jsfiddle.net/stackit/uzjafamo/8/

代码

enyo.kind({
    name: "Board",
    kind: "enyo.Control",
    paper: null,
    create: function(){
       this.inherited(arguments);
    },
    rendered: function(){
         this.inherited(arguments);  
        if(this.hasNode()){
            paper = Raphael(this.hasNode().id, 100, 100);
          }

    }
})


enyo.kind({
    name: "pages",
    kind: "enyo.Control",
    create: function(){
        this.inherited(arguments);
        this.loadView();
    },
    loadView: function(){
        if(!this.$.board){
            var com = this.createComponent({
                name: "board",
                kind: "Board",
            },{
                owner: this
            });
            com.render();
        }
    }
});



new pages().renderInto(document.getElementById("cans"));

【问题讨论】:

    标签: javascript svg raphael enyo


    【解决方案1】:

    我看了你的小提琴,发现有一点可以改进。 jsFiddle 容器最初给我带来了一些麻烦,直到我出于某种原因分叉了它。

    这是我想出的:http://jsfiddle.net/Djspaceg/5qyLej05/4/

    enyo.kind({
        name: "Board",
        kind: "enyo.Control",
        paper: null,
        create: function () {
            this.inherited(arguments);
        },
        rendered: function () {
            this.inherited(arguments);
            if (this.hasNode() && !this.paper) {
                this.generateRaphael();
            }
        },
        generateRaphael: function () {
            this.paper = Raphael(this.hasNode().id, 100, 100);
        }
    });
    
    enyo.kind({
        name: "pages",
        kind: "enyo.Control",
        create: function () {
            this.inherited(arguments);
            this.loadView();
        },
        loadView: function () {
            if (!this.$.board) {
                var com = this.createComponent({
                    name: "board",
                    kind: "Board",
                });
                com.render();
            }
        }
    });
    
    new pages().renderInto(document.getElementById("cans"));
    

    它只是生成一个空的 Raphael 画布。

    干杯!

    【讨论】:

    • 我试图避免 div id=pages_board 并在 div id=pages 下生成 svg
    • 您可以在主页面元素的渲染函数中简单地渲染画布。 jsfiddle.net/Djspaceg/5qyLej05/5
    • 我意识到我将 create 方法保留在原位,但实际上并没有必要。有关详细信息,请参阅更新的小提琴:jsfiddle.net/Djspaceg/5qyLej05/6(另外,如果这解决了您的问题,请投票或标记为正确;非常感谢。)
    • 我的意思是 ENYO 类型不应该生成默认 div。它只应该生成 SVG。那么在这方面你可以删除 div id=pages 吗?我们如何才能访问 SVG?是通过this.$.svg吗?
    • 您可以通过this.paper 访问生成的Raphael 对象。 SVG 元素本身是由 Raphael 生成的,而不是 enyo。您可以通过pages.paper 访问暴露的 Raphael 对象
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 2021-10-02
    • 2012-03-31
    • 2010-10-21
    • 2018-04-03
    相关资源
    最近更新 更多