responsive tentative

master
pisouvigne 5 years ago
parent 9da455d750
commit 51c9d6814b

@ -156,3 +156,12 @@ function calculNombreSwitch(){
} }
function resize(){
console.log(window.innerWidth);
stage.scale({ x: 1, y: 1 });
stage.draw();
console.log(stage);
}

@ -63,6 +63,7 @@
</div> </div>
<div id="play-container"></div> <div id="play-container"></div>
<script> <script>
var mobile = false;
var switchs = [], lineCount = [], logiques = [],lines = [], endLines = [],end, switchsInfo= [], switchsInfoCopy = [],lineRemove = []; var switchs = [], lineCount = [], logiques = [],lines = [], endLines = [],end, switchsInfo= [], switchsInfoCopy = [],lineRemove = [];
var niveauActuel = localStorage.getItem("niveau"); var niveauActuel = localStorage.getItem("niveau");
@ -76,6 +77,7 @@
let container = document.getElementById('play-container'); let container = document.getElementById('play-container');
container.style.height = innerHeight /100*80 + "px"; container.style.height = innerHeight /100*80 + "px";
var width = container.offsetWidth; var width = container.offsetWidth;
var height = container.offsetHeight;
@ -85,7 +87,7 @@
x: 20, x: 20,
y: 1000,*/ y: 1000,*/
width: width, width: width,
height: window.innerHeight, height: height,
}); });
stage.add(layer); stage.add(layer);
@ -102,6 +104,35 @@
modal.style.display = "none"; modal.style.display = "none";
} }
} }
fitStageIntoParentContainer();
function fitStageIntoParentContainer() {
if(window.innerWidth < window.innerHeight && mobile == false){
stage.rotate(90);
stage.x(stage.getX() + stage.height());
stage.draw();
mobile=true;
}else if(mobile){
stage.rotate(0);
stage.draw();
mobile=true;
}
var container = document.querySelector('#play-container');
// now we need to fit stage into parent
var containerWidth = container.offsetWidth;
// to do this we need to scale the stage
var scale = containerWidth / width;
stage.width(width * scale);
stage.height(height * scale);
stage.scale({ x: scale, y: scale });
stage.draw();
}
window.addEventListener('resize', fitStageIntoParentContainer);
</script> </script>
</body> </body>
</html> </html>

@ -0,0 +1,26 @@
<html>
<head>
<title>onresize test</title>
</head>
<body>
<p>Resize the browser window to fire the resize event.</p>
<p>Window height: <span id="height"></span></p>
<p>Window width: <span id="width"></span></p>
<script type="text/javascript">
var heightOutput = document.querySelector('#height');
var widthOutput = document.querySelector('#width');
function resize() {
heightOutput.textContent = window.innerHeight;
widthOutput.textContent = window.innerWidth;
}
window.onresize = resize;
</script>
</body>
</html>
Loading…
Cancel
Save