I added the viewport with properties allowing zooming/scaling. And I added these to the native code:
WebSettings settings = super.appView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(true);
settings.setSupportZoom(true);
I am able to zoom, but along with my view, ion-header-bar
and ion-nav-bar
gets zoomed. I tried giving the header css, to keep it fixed:
position: fixed;
top: 0px;
left: 0px;
but still, it'd get zoomed.
My index.html has an ion-header-bar
, which contains an image.
The templates go into
<ion-nav-view class="has-header"></ion-nav-view>
The template in which I require zooming in a particular div is having a 'ion-view` and it looks like:
<ion-view>
<ion-nav-bar class="bar-stable">
<ion-nav-buttons side="right">
icon1
</ion-nav-buttons>
<ion-nav-buttons side="left">
icon2
</ion-nav-buttons>
</ion-nav-bar>
<div>
Multiple divs in here, which are containers for html and css data we receive via AJAX requests. And this is here I need zooming in.
</div>
</ion-view>
PS: Would it matter if I add a full HTML code(with meta viewport, no header, but body and divs) inside the ion-view
?
I wanted to get similar functionality and was able to get it to work using ion-scroll.
<ion-scroll zooming="true" direction="xy" style="width: 100%; ">
<div></div>
</ion-scroll>
Another solution could be to use hammerjs for multi-touch gestures and map pinch out and pinch in to zoom the content using css.
Something like this:
var hammerTime = new Hammer.Manager($('div.youWantToScale')[0], {touchAction: "pan-x pan-y"});
var pinch = new Hammer.Pinch();
var lastZoom;
hammerTime.add(pinch);
hammerTime.on("pinchout pinchin", function(e) {
var currentZoom = Number($('div.youWantToScale').css("zoom"));
if (lastZoom) {
var newZoom = currentZoom + (e.scale - lastZoom);
//bounds checking for your zoom, min=1 and max=3 here
newZoom = newZoom < 1 ? 1 : (newZoom > 3 ? 3 : newZoom);
$('div.youWantToScale').css("zoom", newZoom);
}
lastZoom = e.scale;
});
hammerTime.on("pinchstart", function (e) {
//Seems clunky, but reset the lastZoom on a new pinch
lastZoom = undefined;
});