admin管理员组

文章数量:1415491

I am designing a UI that uses jointjs to draw a graph.

I need to change the background color of the Paper but I see that changing the .viewport css (e.g. background-color: #ff0000; ) this doesn't affect the appearance of the svg.

How can I add color in the background of the jointjs Paper?

thanks

I am designing a UI that uses jointjs to draw a graph.

I need to change the background color of the Paper but I see that changing the .viewport css (e.g. background-color: #ff0000; ) this doesn't affect the appearance of the svg.

How can I add color in the background of the jointjs Paper?

thanks

Share Improve this question asked Sep 24, 2015 at 14:02 theosemtheosem 1,2043 gold badges12 silver badges22 bronze badges 2
  • 1 create a rect the size of the viewport and set it to the colour you want. – Robert Longson Commented Sep 24, 2015 at 14:08
  • @RobertLongson thanks for the answer. I don't see this as a clean approach, meaning that I should then keep track of another cell in case of resize etc. Are you sure there is no other way to do this? thanks – theosem Commented Sep 24, 2015 at 14:11
Add a ment  | 

4 Answers 4

Reset to default 3

When initializing paper, add background option to paper

var paper = new joint.dia.Paper({
    background: {
       color: '#ff0000'
    }                                                                         
});

You can find more info at Jointjs paper documentation.

The paper is just a normal HTML <div> element so you can set the background-color: #ff00000 on that <div> element rather than on the internal .viewport SVG <g> element.

I changed the svg element style in css to change the paper background color and it works for me. Here is an example.

svg {
    background-color: blue;
}

If you want to change the background of a paper on runtime:

paper.options.background = { color: '#FF0000' };
paper.render()

Testet with jointjs v4.1

本文标签: javascriptjointjs paper background colorStack Overflow