@@ -2,59 +2,43 @@ const customScaleDiv = document.querySelector(
22 ".custom-scale-div"
33) as HTMLElement ;
44
5+ // CustomScaleCalc
6+ // This is a method I created myself, and I find it very interesting. I named it customScaleCalc.
7+ // Adjusts the scale and rotation of the element based on the window size.
8+ // For landscape displays, scales the element by height for optimal viewing.
9+ // For portrait displays, rotates the element 90 degrees and scales down for mobile compatibility.
10+ // Ultimately, in the mobile device's browser, the application is correctly displayed with a 90-degree rotation,
11+ // allowing devices with different sizes to use the program. Ensures the app looks good on any screen size by recalculating on window resize.
12+
513const customScaleCalc = ( ) => {
614 const pageWidth = window . innerWidth ;
715 const pageHeight = window . innerHeight ;
816
917 if ( pageWidth > 270 ) {
1018 if ( pageHeight > pageWidth ) {
11- // console.log(pageWidth, pageHeight);
12-
1319 customScaleDiv . classList . add ( "custom-scale-calc" ) ;
1420
15- // let scale = 1 - ((pageHeight / pageWidth) * 0.2) / (900 / 477);
16-
17- // customScaleDiv.style.transform = `scale(${scale}) rotate(90deg)`;
18-
19- // customScaleDiv.classList.remove("custom-scale-calc");
20- // customScaleDiv.style.transform = "";
21-
2221 let scaleValue = 0 ;
23-
2422 if ( pageHeight / pageWidth > 1130 / 780 ) {
2523 scaleValue = ( 1 * pageWidth ) / 695 ;
2624 } else {
2725 scaleValue = ( 0.7 * pageWidth ) / 695 ;
2826 }
2927
30- customScaleDiv . style . transform = `scale(${ scaleValue } ) rotate(90deg)` ;
31- customScaleDiv . style . display = "block" ;
32-
33- // customScaleDiv.style.top = `${(pageHeight - 920 * scaleValue)/2}px`;
34-
35- // customScaleDiv.style.transformOrigin = "top";
36-
37- // console.log("scale", scale);
28+ customScaleDiv . style . transform = `scale(${ scaleValue } ) rotate(90deg) translate(50%, -50%)` ;
29+ customScaleDiv . style . top = `${
30+ ( pageHeight - 1000 * scaleValue ) / 2
31+ } px`;
3832 } else {
3933 customScaleDiv . classList . remove ( "custom-scale-calc" ) ;
40- // customScaleDiv.style.transform = "";
34+
4135 const scaleValue = ( 1 * pageHeight ) / 695 ;
4236
4337 customScaleDiv . style . transform = `scale(${ scaleValue } )` ;
44- customScaleDiv . style . display = "block" ;
45- customScaleDiv . style . transformOrigin = "top" ;
38+ customScaleDiv . style . width = `${ pageWidth / scaleValue } px` ;
4639 }
4740 }
4841} ;
4942
5043customScaleCalc ( ) ;
5144window . addEventListener ( "resize" , customScaleCalc ) ;
52-
53- // Description: This is a method I created myself, and I find it very
54- // interesting. I named it customScaleCalc. What it does is, when the
55- // height of the screen is greater than the width (as in the case of some
56- // smartphones), it rotates the screen by 90 degrees and scales down the
57- // content with a certain ratio. Ultimately, in the mobile device's
58- // browser,the application is correctly displayed with a 90-degree
59- // rotation, allowing devices with different sizes to use the program.
60- // This calculation of how to display the screen is performed.
0 commit comments