in my sketch i create some elements (buttons) and give to them a position according to the windowWidth && windowHeight. As for desktop not any problems. As for phones or tablets it s more difficult but it is possible, knowing that portrait is the default mode and that anyway you can capture at start the device orientation.
When the sketch starts (on phone or tablet) everything is ok.
Now the user changes the orientation, let us say from portrait to landscape.
I know how to capture this event with JavaScript: here is the code i use for that:
window.addEventListener("orientationchange", function() {
alert(window.orientation);
if(window.orientation = 0 || window.orientation =360){
boutonpropos.position(windowWidth -50,50);
}else if(window.orientation=180){
boutonpropos.position(windowWidth -50,50);
}else if(window.orientation =90){
boutonpropos.position(windowHeight -50,50);
}else if(window.orientation = -90){
boutonpropos.position(windowHeight -50,50);
}
// location.reload();
}, false);
the event is captured and the alert is fired correctly. But the position of the button does not change; if the user changes the orientation 3 or 4 times everything begins to be completely weird. As for know i decided to “reload()” and of course the button(s) are correctly displayed but that is not a good solution…
Any idea?
thanks in advance
PS: complete code is here, the button is “/”; reload() is used but i can comment it.
https://www.akenaton-docks.fr/DOCKS-datas_f/collect_f/auteurs_f/C_f/CASTELLIN_f/anim_f/lasomme_F/lepoemeWebJS.html