transform-scale
Stack Overflow Example for a fixed background that does not stay fixed when scaled.
by Tim Downey
HTML
<canvas id="img1">
</canvas>
<div id="outer">
<div class="opaque">
Make the window small enough so scroll bars appear. Scroll to reveal the fixed background.
</div>
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
<div class="opaque">
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
CSS
div#outer {
position: relative;
height: 300px;
width: 300px;
border: thick solid green;
padding: 0;
margin: 0;
z-index:100;
}
div.opaque {
background: yellow;
}
#img1 {
position: fixed;
width: 300px;
height: 300px;
background: pink;
border: thick solid red;
zindex:90;
}
JavaScript
function scale(rat, container) {
var element = document.getElementById(container);
element.style.transform = 'scale(' + rat + ')';
element.style.transformOrigin = '0 0';
}
function scaleAll(rat) {
scale(rat, "outer");
scale(rat, "img1");
}
scaleAll(0.5)
var c = document.getElementById("img1");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(95,50,40,0,2*Math.PI);
ctx.stroke();