通过手机缩放页面时,使标头不更改大小

  • 本文关键字:手机 缩放 javascript css
  • 更新时间 :
  • 英文 :


因此,有一个应用程序链接到两个不同的网页。第一个是由我制作的,它的响应能力很快,所以当它加载在手机上时,一切都非常适合。

另一家是由我工作的公司创造的,并且没有响应。

现在,我应该在这两个页面的顶部添加一个条,当它们在应用程序中加载时,栏中的两个页面都需要具有相同的尺寸。我不能在不响应的页面上更改任何内容,只有顶部的栏。

让我们以900px和360px为例,一页缩放以适合360px的iPhone,而另一页则保持900px宽度,以便将其缩放以通过手机放在移动屏幕上。

http://imgur.com/6tv1idt

我需要为900px宽度的条制作一个条,即使由360px宽度页面上的高度始终具有相同的高度,即使它被不同的手机缩放。(缩小到不同的宽度/高度)

即使页面的其余部分被缩放,有什么方法可以设置通过电话缩放来忽略的元素的高度?

我认为,如果您只是为该栏定义width: 100%;,它应该可以工作,也可以在非响应页面上。

尝试将其添加到文档<meta name="viewport" content="width=device-width, initial-scale=1">的头部。由于您的问题是可怕的,因此甚至很难理解您想要的或试图修复的内容。

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The rest of the head below... -->
</head>

我知道这不是措辞,所以很容易理解,但也许有人会搜索类似的东西,无论如何都在这里最终出现,所以这就是我解决的方式。

//get the width of the browser without the scaling 
//if the window is smaller than 260 my paged stopped scaling and started to use a horizontal scrollbar instead
//the minimum depends on your webpage I think. (Change the 260 to the minimum width of your page.
currentWidth = screen.width > 260 ? screen.width : 260;
//get the relative size depending on the size of the non-scaling webpage.
//The page I worked with had a width of 1050.
//If the browser is wider than the page set the size to 1.
relativeSize = screen.width < 1050 ? (1050/currentWidth) : 1;

获得该值后,您可以使用相关的 *(不缩放时的大小),即使页面大小,它最终也会变为相同的大小。

我将其设置为Onload并进行重大攻击事件,并在页面大小更改时调整标题大小。即,当某人翻转电话时,您可能想再次调整大小。

编辑:screen.width而不是窗口。

最新更新