Zoom in and zoom out functionality in jquery mobile or javascript - Stack Overflow

Is there any good way for zoom in and zoom out functionality in a page using jQuery mobile. I goggled i

Is there any good way for zoom in and zoom out functionality in a page using jQuery mobile. I goggled it and found

window.parent.document.body.style.zoom = 1.5;

Is there any better way to do zoom in and zoom out functionality in jQuery mobile?

Is there any good way for zoom in and zoom out functionality in a page using jQuery mobile. I goggled it and found

window.parent.document.body.style.zoom = 1.5;

Is there any better way to do zoom in and zoom out functionality in jQuery mobile?

Share Improve this question edited Jan 22, 2014 at 13:28 Xyz 6,0136 gold badges42 silver badges59 bronze badges asked Jul 3, 2013 at 5:17 ShrutiShruti 1,5748 gold badges31 silver badges67 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Here is a sample workaround, DEMO http://jsfiddle/yeyene/aGuLE/

$(document).ready(function () {
    $('#zoomIn').on('click', function () {
        zoomIn(1.2);
    });
    $('#zoomOut').on('click', function () {
        zoomOut();
    });
});

function zoomIn(zoomLev) {
    if (zoomLev > 1) {
        if (typeof (document.body.style.zoom) != "undefined") {
            $(document.body).css('zoom', zoomLev);
        }else {
            // Mozilla doesn't support zoom, use -moz-transform to scale and pensate for lost width
            $('#divWrap').css({
                "-moz-transform": 'scale(" + zoomLev + ")',
                width: $(window).width() / zoomLev
            });
        }
    }
}

function zoomOut() {
    $(document.body).css({
        zoom : '',
        position : '',
        left: "",
        top: "",
        "-moz-transform" : "",
        width : ''  
    });
}

If you are using Jquery mobile you need to check your the meta data in <head> of your file

<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />

if content="user-scalable=no is defined in your viewport metadata this will prevent you from scaling or zooming in and out

Try this. You must have already a meta viewport somewhere.

var viewportmeta=$("meta[name='viewport']"); //find a viewport meta

viewportmeta.attr("content_original", viewportmeta.attr("content")); //store the initial value
viewportmeta.attr("content", "user-scalable=yes, width=device-width minimum-scale=1, maximum-scale=1"); //make current viewport full zoom out

//do your things... 

viewportmeta.attr("content", viewportmeta.attr("content_original")); //then return back to old  viewport conditions

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742279439a4414212.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信