如何在JointJs中设置矩形的背景图像? [英] How to set background image for a rectangle in JointJs?

查看:421
本文介绍了如何在JointJs中设置矩形的背景图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的JointJs应用程序中为矩形设置背景图像属性?

How to set background image attribute for a rectangle in my JointJs application ?

推荐答案

矩形对象本身没有该属性....该怎么做才能创建图像对象本身:

Rectangle object doesn't have that attribute perse....what you can do it's create an image object itself:

var image = new joint.shapes.basic.Image({
    position : {
        x : 50,
        y : 40
    },
    size : {
        width : 16,
        height : 16
    },
    attrs : {
        image : {
            "xlink:href" : "images/background.png",
            width : 16,
            height : 16
        }
    }
});

graph.addCell(image);

然后,您可以根据需要使用其attrs进行游戏,如果您想绘制图表,甚至可以创建端口并在以后设置箭头.另一种方法是创建一个矩形对象,然后在上方作为封面创建此图像对象(以防您需要从矩形到代码的特定属性).告诉我它的运行方式.

Then you can play as you need with the attrs of it, you can even create ports and set arrows later if you wish to do diagrams. Other way it's to create a rectangle object and then create this image object above as a cover (in case you need specific attrs from rectangle to code).Tell me how it goes.

这篇关于如何在JointJs中设置矩形的背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆