Код сценария, который я использовал: < /p>
Код: Выделить всё
Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)
var w = window.innerWidth;
var h = window.innerHeight;
var x = document.getElementById("demo");
x.innerHTML = "Browser width: " + w + ", height: " + h + ".";
< /code>
На веб -странице выводит следующее < /p>
Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)
Browser width: 1920, height: 892.
< /code>
, который, как я предполагаю, верен, так как он выглядит правильно для разрешения экрана.
Я затем передал переменные в php < /p>
< /code>
Результат < /p>
Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)
Browser width: 1920, height: 892.
$STR_phpwidth is a string variable, and has a value of 1920
$STR_phpheight is a string variable, and has a value of 892
< /code>
Я хочу иметь возможность разрабатывать проценты размера экрана, поэтому я преобразовал строковые переменные в Float /Doubles < /p>
$DOU_floatwidth = floatval($STR_phpwidth);
$DOU_floatheight = floatval($STR_phpheight);
echo '$DOU_floatwidth is a ' . gettype($DOU_floatwidth) . ' variable, and has a value of ' . $DOU_floatwidth . '
';
echo '$DOU_floatheight is a ' . gettype($DOU_floatheight) . ' variable, and has a value of ' . $DOU_floatheight . '
';
< /code>
и выход теперь < /p>
Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)
Browser width: 1920, height: 892.
$STR_phpwidth is a string variable, and has a value of 1920
$STR_phpheight is a string variable, and has a value of 892
$DOU_floatwidth is a double variable, and has a value of 0
$DOU_floatheight is a double variable, and has a value of 0
< /code>
Как видите, строка не была передана и преобразована в Float /Double. Я пробовал несколько разных методов, включая $ dou_floatwidth = (float) $ str_phpwidth; Код: Выделить всё
$STR_phpwidth = "1920";
$STR_phpheight = "892";
< /code>
Тогда я ожидаю полный вывод. < /p>
Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)
Browser width: 1920, height: 892.
$STR_phpwidth is a string variable, and has a value of 1920
$STR_phpheight is a string variable, and has a value of 892
$DOU_floatwidth is a double variable, and has a value of 1920
$DOU_floatheight is a double variable, and has a value of 892
$DOU_onepercent is a double variable
1% of the screen width is 19.2px
< /code>
Полная страница /код: < /p>
Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)
var w = window.innerWidth;
var h = window.innerHeight;
var x = document.getElementById("demo");
x.innerHTML = "Browser width: " + w + ", height: " + h + ".";
Подробнее здесь: https://stackoverflow.com/questions/794 ... ble-in-php