简体   繁体   English

如何基于屏幕分辨率触发html / php文件

[英]how to trigger html/php file base on screen resolution

i am developing one wordpress responsive website. 我正在开发一个wordpress响应式网站。 but now i am facing problem menu issue. 但现在我面临着菜单问题。 please see the bellow image for my navigation. 请查看下面的图片以进行导航。 on top black bar "Check our Town" will have drop down menu and on blue bar About Us also have drop down menu 在顶部的黑色栏“检查我们的小镇”上将具有下拉菜单,而在蓝色栏上“ 关于我们”也具有下拉菜单

在此处输入图片说明

so i want when screen resolution bellow 800 then top menu and logo part will be different. 所以我想当屏幕分辨率在800以下时,顶层菜单和徽标部分会有所不同。 i know one way like i can make separate header part then hide it via css and call it via css media query. 我知道一种方法,例如我可以制作单独的标题部分,然后通过CSS隐藏它并通过CSS媒体查询调用它。 for that i need to keep that code always in body. 为此,我需要始终将这些代码保留在正文中。 but i don't want it i want it will code will be in body only when it required. 但我不希望它只在需要时才在体内进行编码。

say if make top area separate html/php file if i can call it when screen resolution will 800/480 etc that would be work i guess. 说如果使顶部区域分开的html / php文件,如果我可以在屏幕分辨率为800/480等时调用它,那我会猜想。 i can be possible thru php/js but i have no idea how. 我可以通过php / js实现,但我不知道如何。

see the image there is two part for navigation one is black area and another is blue area. 看到图像有两个导航部分,一个是黑色区域,另一个是蓝色区域。 when i will be bellow 800px it will be all menu in one drop down. 当我将波纹管800像素时,它将是一个下拉菜单中的所有菜单。

see bellow menu i want this type when screen resolution bellow 800px 屏幕分辨率低于800像素时,请参见下面的波纹管菜单,我要使用此类型

在此处输入图片说明

I wouldn't recommend the ajax to load the 2 navs. 我不建议Ajax加载2个导航。 Its adding an extra http request, which is slower than just giving both desktop and mobile the little bit of extra markup required. 它添加了一个额外的http请求,这比仅向桌面和移动设备提供所需的一点额外标记要慢。

I think using media queries is your best approach. 我认为使用媒体查询是最好的方法。

This is what i think you're trying todo: http://jsfiddle.net/krismeister/CNr5y/ 这就是我想您要尝试做的事情: http : //jsfiddle.net/krismeister/CNr5y/

The relevevant portion is the @media screen and (min-width:800px){ 相关部分是@media screen and (min-width:800px){

I think the only way to achieve it is to use ajax. 我认为实现此目标的唯一方法是使用Ajax。 Send an empty page to a client, check window size, and request the content via ajax with a screen width as a param. 将空白页发送给客户端,检查窗口大小,并通过ajax请求内容,并以屏幕宽度作为参数。

i am not so good on jquery and json.. do you bellow way can work ? 我对jquery和json不太满意。

$(function() {
    $.post('some_script.php', { width: 800px }, function(json) {
        if(json.outcome == 'success') {
           header-800px.php;
        } else {
            header.php;
        }
    },'json');
});

ref : Getting the screen resolution using PHP 参考: 使用PHP获取屏幕分辨率

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM