没有办法做到"后端媒体查询和QUOT;与JS和PHP? [英] Any way to do "backend media queries" with JS and PHP?

查看:104
本文介绍了没有办法做到"后端媒体查询和QUOT;与JS和PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作项目由网格显示的内容。我想在网格中各项调整到第四个视口的大小。这会很容易与JavaScript,但有一些需要注意的每个项目的大小的后端东西:

The project I am working on consists of a grid showing content. I would like to resize each item on the grid to a fourth of the viewport's size. This would be very easy with Javascript, but there is some backend stuff that needs to be aware of the size of each item:

我使用Timthumb项的图像调整到其appropiate的大小,所以我需要检测视口的宽度,并发送此时,相应的值(视口的宽度/ 4),供应每个项目的PHP,所以它告诉Timthumb此时,相应尺寸来使用。

I am using Timthumb to resize the image of item to its appropiate size, so I would need to detect the viewport's width, and send the appropiate value (the viewport's width / 4) to the php that serves each item, so it tells Timthumb the appropiate size to use.

什么是对这个问题最好的办法?

What would be the best approach to this problem?

推荐答案

如何申请页面,在$如果(文件)。就绪,检测视口的大小使用jQuery,并通过它的AJAX请求?

How about when requesting the page, in $(document).ready, detect the size of viewport using jQuery and pass it in an AJAX request?

$(document).ready(function () {
    var height = $(window).height();
    var width = $(window).width();
    $.ajax({
        type: 'POST',
        url: image.php,
        data: {
            "height": height,
            "width": width
        },
        success: function (data) {
            $("#viewarea").html(data);
        },
    });
});

在PHP端你可以得到它,并返回数据。

at PHP side you can just get it and return the data

$_POST['height']
$_POST['width']

这篇关于没有办法做到"后端媒体查询和QUOT;与JS和PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆