complete styles for cross browser CSS zoom

后端 未结 5 1001
小鲜肉
小鲜肉 2020-11-28 04:54

I am finding it hard to get fully cross browser CSS zoom properties ..what I\'ve is only these

zoom: 2;
-moz-transform: scale(2);
5条回答
  •  迷失自我
    2020-11-28 05:25

    If scripting is feasible then you can avoid both the collision of multiple supported zoom properties and the browser sniffing by using future-proof feature detection.
    Note: I'm using jQuery here for convenience, but it could be written without it.

    CSS:

    .zoom {
        -moz-transform-origin: 0 0;
        -o-transform-origin: 0 0;
        -webkit-transform-origin: 0 0;
    }
    

    HTML:

    Foobar

    Script (One-Off Initialisation)

    var strPropZoom = "zoom";
    var blnPropZoomUseScale = false;
    
    $(function() {
        var jqBody = $("body");
    
        // Determine the supported 'zoom' method
        switch (true) {
            case Boolean(jqBody.css("zoom"))              : break;
            case Boolean(jqBody.css("-moz-transform"))    : strPropNameZoom = "-moz-transform";    blnPropZoomUseScale = true; break;
            case Boolean(jqBody.css("-o-transform"))      : strPropNameZoom = "-o-transform";      blnPropZoomUseScale = true; break;
            case Boolean(jqBody.css("-webkit-transform")) : strPropNameZoom = "-webkit-transform"; blnPropZoomUseScale = true; break;
        }
    })
    

    Then when zooming is required simply invoke:

    var intZoom = 2.5; // NB: This could be calculated depending on window dimensions
    $(".mySelectorClass")
        .css(
            strPropZoom
            ,(blnPropZoomUseScale ? "scale(" + intZoom + ")" : intZoom)
        )
        .addClass("zoom");
    

提交回复
热议问题