Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
195
rated 0 times [  198] [ 3]  / answers: 1 / hits: 16984  / 9 Years ago, fri, march 6, 2015, 12:00:00

I'm trying out Paper.js for fun, but it seems I'm already stuck at the very start.



Adding resize=true to the canvas tag is supposed to make the element as high and wide as the browser window. However, doing that results in some rather strange behavior.



I expected the canvas to adjust itself to the viewport right after loading the page, but it didn't do so, which is why I initially thought it didn't resize at all. What actually happens, though, is even more bizarre: The canvas starts out at its default size of 300x150, and when I resize the viewport, it grows - slowly, but indefinitely.



For the record, I've tried using data-paper-resize=true or just resize instead, or using Chrome instead of Firefox - all to no avail.



I'm not expecting an answer if this problem is caused by some inexplicably weird setup on my end. I am wondering, however, if the problem is common (or even known to exist at all) and has known causes and solutions.



Here's the code I'm using:



<!doctype html>
<html>
<head>
<meta charset=utf-8>
<script type=text/javascript src=paper-full.min.js></script>
<script type=text/paperscript canvas=myCanvas>

var path = new Path();
path.strokeColor = 'black';
path.moveTo(new Point(120, 120));
path.lineTo(new Point(500, 500));

</script>
</head>
<body>
<canvas id=myCanvas style=border: 1px dotted red; resize=true></canvas>
</body>
</html>

More From » paperjs

 Answers
34

Add the following CSS to your project:



<style type=text/css>
html,
body {
margin: 0;
overflow: hidden;
height: 100%;
}

/* Scale canvas with resize attribute to full size */
canvas[resize] {
width: 100%;
height: 100%;
}
</style>

[#67545] Wednesday, March 4, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
monetm

Total Points: 615
Total Questions: 103
Total Answers: 119

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
monetm questions
Fri, Feb 26, 21, 00:00, 3 Years ago
Wed, Sep 9, 20, 00:00, 4 Years ago
Sun, Jul 26, 20, 00:00, 4 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
;