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?
Here is a sample workaround, DEMO http://jsfiddle.net/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 compensate 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 : ''
});
}
see this link is the best i saw ever :- http://jaukia.github.io/zoomooz/
and this if you like manual zoom in zoom out:- http://jsfiddle.net/videsignz/KGY7c/
var imagesize = $('img').width();
$('.zoomout').on('click', function(){
imagesize = imagesize - 5;
$('img').width(imagesize);
});
$('.zoomin').on('click', function(){
imagesize = imagesize + 5;
$('img').width(imagesize);
});
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.