最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Change initial scale with javascript - Stack Overflow

programmeradmin0浏览0评论

I made an app with phonegap. I didnt wantet to use media queries because so i had to change all parameters for diffrent viewport sizes. My idea was that i only change the inital scale of the html document with javascript. I know that i can change the initial scale with an function like i show here:

 if (document.documentElement.clientWidth < 480) {
        document
            .querySelector("meta[name=viewport]")
            .setAttribute('content', 'initial-scale=0.4', 'maximum-scale=0.4', 'width=768');
    };

but i want that the initial scale is at an width of 320 pixel of the viewport 0 or in other words 100%. And at a viewport width of 720 (Galaxy S3) 110% or in other words initial scale of 0.1. For all the viewport sizes that lay between javascript should calculate the scale. I have no idea how to achieve this! Im very happy about every help! Hope you unterstood me, im from germany!

I made an app with phonegap. I didnt wantet to use media queries because so i had to change all parameters for diffrent viewport sizes. My idea was that i only change the inital scale of the html document with javascript. I know that i can change the initial scale with an function like i show here:

 if (document.documentElement.clientWidth < 480) {
        document
            .querySelector("meta[name=viewport]")
            .setAttribute('content', 'initial-scale=0.4', 'maximum-scale=0.4', 'width=768');
    };

but i want that the initial scale is at an width of 320 pixel of the viewport 0 or in other words 100%. And at a viewport width of 720 (Galaxy S3) 110% or in other words initial scale of 0.1. For all the viewport sizes that lay between javascript should calculate the scale. I have no idea how to achieve this! Im very happy about every help! Hope you unterstood me, im from germany!

Share Improve this question asked Feb 21, 2013 at 19:20 Em StaEm Sta 1,70610 gold badges29 silver badges43 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

try this:

 if (document.documentElement.clientWidth < 480) { 
    document.querySelector("meta[name=viewport]").setAttribute(
          'content', 
          'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0');
 }

Reference : Can I change the viewport meta tag in mobile safari on the fly?

发布评论

评论列表(0)

  1. 暂无评论