Screen Rotation adaptation on mobile with javascript and html #752
Uhrien92
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Greetings,
I've made a solution to let the scanner UI adapt for both landscape and portrait:
Since aspect ratio and qrbox changes are not possible with the scanner active, i've opted for a stop and start solution on screen rotation:
`<script type="text/javascript">
window.div_img = document.getElementById("reader_img");
window.div_reader = document.getElementById("reader");
window.header = document.getElementById("header_navbar");
window.body = document.getElementsByTagName('body')[0];
window.background = document.getElementById("background");
window.html5QrCode
let qrboxWidth;
let qrboxHeight;
let config;
let divAspectRatio;
let width = window.outerWidth;
let height = window.outerHeight;
//landscape orientation
if(width > height)
{
// If width is less than 1204, we are not on a PC so hide header bar for more space
if(width < 1024)
{
$("#header_navbar").hide();
body.style.paddingTop = "";
background.style.height = "180vh";
}
*/
}
// portrait orientation
else if(height > width)
{
qrboxWidth = 250;
qrboxHeight = 250;
divAspectRatio = 1.333334;
/**
*/
if (devices && devices.length) {
if(typeof div_img !== 'undefined')
{
div_img.remove();
}
var cameraId = devices[1].id;
}
}).catch(err => {
// handle err
alert(err);
});
///// At screen rotation
window.addEventListener("orientationchange", (event) => {
width = window.outerWidth;
height = window.outerHeight;
// stop scanner
html5QrCode.stop();
});
const qrCodeSuccessCallback = (decodedText, decodedResult) => {
//alert(decodedText);
let action = document.getElementById("action").value;
};
</script>`
Sorry for bad coded and uncoded writing but this is my first post here on github. Hope this can help someone who need the same feature
Beta Was this translation helpful? Give feedback.
All reactions