有没有办法将视口的比例动态重置为1.0

use*_*986 14 javascript iphone mobile viewport ipad

我在移动网上商店工作并在实现产品缩放功能时陷入困境

单击图像后,允许使用"用户可缩放",并将最大比例设置为10.0.当用户使用捏合手势放大产品时,一切正常.但在关闭缩放的图像后,比例不会重置为1.0.

有没有办法动态重置视口的比例值."初始规模"似乎不起作用,也没有将"最小规模"和"最大规模"重置为1.0

iPhone/iPad上出现问题

似乎有一个解决方案,但我不知道我应该在这篇文章中应用哪个元素: 如何在没有完整页面刷新的情况下重置视口缩放?

"你需要使用-webkit-transform:scale(1.1); webkit transition."

但我不知道风格应用于哪个元素.

以下是一些用于说明问题的代码.

在视口的元标记中看起来像这样:

<meta name="viewport" content="user-scalable=no, width=device-width, height=device-height, minimum-scale=1.0, maximum-scale=1.0" />
Run Code Online (Sandbox Code Playgroud)

页面的其余部分如下所示:

<div id="page">
    <img src="images/smallProductImage.jpg">
</div>

<div id="zoom">
    <div class="jsZoomImageContainer"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

这是javascript ::

zoom:{
    img: null,
    initialScreen:null,

    load:function(src){             

        //load the image and show it when loaded

        showLoadingAnimation();
        this.img = new Image();
        this.img.src = src;

        jQuery(this.img).load(function(){
            zoom.show();
        });
    },

    show:function(){

        var screenWidth, screenHeight, imageWidth, imageHeight, scale, ctx;             

        hideLoadingAnimation();
        jQuery("#page").hide();         
        jQuery("#zoom").show();

        jQuery(".jsZoomImageContainer").empty();
        this.initialScreen =[jQuery(window).width(),  jQuery(window).height()]
        jQuery(".jsZoomImageContainer").append(this.img);               


        imageWidth = jQuery(this.img).width();
        imageHeight = jQuery(this.img).height();

        scale = this.initialScreen[0] / imageWidth ;

        jQuery(this.img).width(imageWidth * scale)
        jQuery(this.img).height(imageHeight * scale)


        jQuery(".jsZoomImageContainer").click(function(){
             zoom.hide();
        });

        jQuery('meta[name="viewport"]',"head").attr("content","user-scalable=yes, initial-scale:1.0, minimum-scale=1.0, maximum-scale=10.0")                 

    },

    hide:function(){                        
        jQuery(".jsZoomImageContainer").empty();                        
        jQuery('meta[name="viewport"]',"head").attr("content","user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0") 

        jQuery("#zoom").hide();
        jQuery("#page").show();

        this.img = null;
        this.initialScreen = null;

    }
}

jQuery("#page img").click(function(){
    zoom.load("images/bigProductImage.jpg");
});
Run Code Online (Sandbox Code Playgroud)

Tro*_*ott 1

根据 ppk 的说法,这种视口操作技术适用于除 Firefox 之外的所有现代浏览器:

<meta id="testViewport" name="viewport" content="width = 380">
<script>
if (screen.width > 740) {
    var mvp = document.getElementById('testViewport');
    mvp.setAttribute('content','width=740');
}
</script>
Run Code Online (Sandbox Code Playgroud)

看来关键是id在标签中设置一个属性meta,这样你就可以用 JS 轻松选择它并替换属性的值content