fix: scale drakonwidget container to fit parent, center with flexbox
This commit is contained in:
1 parent
35ebd2c687
commit
85d47d46b1
1 file changed
+17
-4
+17
-4
@@ -871,6 +871,14 @@ button { font-family: inherit; cursor: pointer; border: none; background: none;
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 400px;
|
height: 400px;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
#drakon-canvas > div {
|
||||||
|
transform-origin: center center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#drakon-canvas canvas {
|
#drakon-canvas canvas {
|
||||||
@@ -1333,10 +1341,15 @@ window.addEventListener('load', function() {
|
|||||||
// Append the widget's container (with canvas) to our #drakon-canvas element
|
// Append the widget's container (with canvas) to our #drakon-canvas element
|
||||||
if (widget.container) {
|
if (widget.container) {
|
||||||
canvasContainer.appendChild(widget.container);
|
canvasContainer.appendChild(widget.container);
|
||||||
canvasContainer.style.display = 'flex';
|
|
||||||
canvasContainer.style.alignItems = 'center';
|
// Scale the container to fit the parent (560px canvas -> fit in ~486px container)
|
||||||
canvasContainer.style.justifyContent = 'center';
|
var containerWidth = canvasContainer.clientWidth;
|
||||||
canvasContainer.style.overflow = 'hidden';
|
var scaleX = containerWidth / 560;
|
||||||
|
var scaleY = (containerWidth / 560) * (420 / 400);
|
||||||
|
widget.container.style.transform = 'scale(' + scaleX + ')';
|
||||||
|
widget.container.style.transformOrigin = 'center center';
|
||||||
|
widget.container.style.width = (560 * scaleX) + 'px';
|
||||||
|
widget.container.style.height = (420 * scaleX) + 'px';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user