简体   繁体   English

是否有可能使用CSS媒体查询获取移动设备的大小并将其发送到php变量

[英]Is it possible to get the size of the mobile device using css media query and send it to php variable

I am redesigning a website which is currently a desktop version to mobile website. 我正在重新设计一个网站,该网站目前是移动网站的桌面版本。

My question is that I have to resize the images according to the screen width of the device . 我的问题是我必须根据设备的屏幕宽度调整图像大小。 i understand that we can do this using media query . 我知道我们可以使用媒体查询来做到这一点。

But the thing is that there is this function in my website which resize the images and save in a directory from where we get the images accordingly for our website because our website is dynamic and people keep posting adds with weird image sizes. 但事实是,我的网站中有此功能,可以调整图像大小并保存在目录中,以便从中获取相应的网站图像,因为我们的网站是动态的,人们不断发布带有怪异图像尺寸的添加内容。

for example the function is like this 例如功能是这样的

$whsize=$this->getSizeImage($id_item,$height,$width,basename($imag[0]))

in the and we just give the values of height and width ourself for now I have given 480 px for both for the mobile device. 在中,我们仅给出自己的高度和宽度值,现在我已经为移动设备给出了480像素。

But when the screen resolution is less than that the image is not in its proper dimension so I wanted to get the width of the screen and call this function getSizeImage() to redo the right size . 但是,当屏幕分辨率小于图像分辨率时,我想获取屏幕的宽度并调用此函数getSizeImage()以重做正确的尺寸。

Is it possible to do it ?? 有可能做到吗?

You can't get any values in PHP variable, because PHP is a Server side scripting language. 您无法在PHP变量中获取任何值,因为PHP是服务器端脚本语言。

You need JavaScript, not PHP. 您需要JavaScript,而不是PHP。

var screenWidth = window.screen.width,
var screenHeight = window.screen.height;

You can then send it to the server via Ajax (with an XmlHttpRequest ). 然后,您可以通过Ajax(带有XmlHttpRequest )将其发送到服务器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用媒体查询的CSS图像交换移动版和桌面版 - css image swap mobile vs desktop using media query 如果两个设备分辨率相似但设备屏幕尺寸(以英寸为单位)不同,如何定位 CSS 媒体查询? - How to target CSS media query if both device resolution is similar but device screen size(in inches) is different? 如何获取设备尺寸(移动设备)? - How to get device size (mobile)? 使用Javascript(和媒体查询)获取CSS样式表属性 - Get CSS style sheet property using Javascript (and media query) JQuery Mobile: <a>使用CSS @media查询</a>修改<a>按钮data-inline =“ true”</a> - JQuery Mobile: modifying <a> button data-inline=“true” using CSS @media query 使用javascript(或css,通过鼠标(或在移动设备中触摸))更改元素的大小,而不考虑jquery ui - Change the size of an element by mouse(or touch in mobile) using javascript (or css ,that's better if possible), not considering the jquery ui 使用 XMLHttpRequest 将 Javascript 变量发送到 PHP 以查询 MySQL。 不工作 - Using XMLHttpRequest to send Javascript variable to PHP to query MySQL. Not working 使用媒体查询后可以更改html吗? - Is it possible to change html after using media query? 使用CSS媒体查询时未打印背景 - Background not printed when using CSS media query 是否可以从Javascript返回CSS媒体查询声明? - Is it possible to return to a CSS media query declaration from Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM