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

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

programmeradmin2浏览0评论

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
发布评论

评论列表(0)

  1. 暂无评论