views:

1427

answers:

3

I use JQTouch for an iPhone app. JQtouch disable by default the possibility to pinch&zoom the page. For one page (containing a big image), i need to enable the pinch & zoom feature. This is easy :

var viewport = $("head meta[name=viewport]");
viewport.attr('content', 'width=320, initial-scale=1, maximum-scale=10.0, minimum-scale=1, user-scalable=1');

But after user has play with the pinch & zoom, I need to dynamically reset the zoom (scale) to the default. I tried to reset the viewport:

viewport.attr('content', 'width=320, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;');

After calling the above code, it's not possible to zoom anymore (because of user-scalable=0;), but it doesn't change the current scale to the default.

I am looking for something like setScale(1), or to change an attribute like current-scale=1

Any idea ?

A: 

Hi Samuel,

Did you ever find a solution to this, I am trying to solve exactly the same issue, not having a lot of luck.

Narinda
I found a solution to zoom an html element (such as image), not with the viewport, but with relatively complex css scaling and scrolling.If you are interested, I can post the code later.
Samuel Michelot
I ended up using css to scale and re-enabled the default events for scrolling. It's not perfect but it's fine for what I am doing at the moment. Would be interested to see how you tackled it though.
Narinda
A: 

Hi, would u guys please tell me what css require to enable scrolling after zooming an html element.

Thanks~

Khalid Gul
It's not possible with CSS only.Here is a nice example with Javascript and CSS transform :http://tlrobinson.net/projects/iphone-light-table/you can play with the code, it's easy to integrate it in your project.
Samuel Michelot
Thanks Samuel. Its really a great one. I will definitely use in my work.
Khalid Gul
+1  A: 

The only way to reset the user scaling is to reload the page :

window.location.reload();

If you don't want to do that, you will need to add a script to zoom dynamically elements such as images with touch events. Here is an example of pinch&zoom with scrolling :

http://tlrobinson.net/projects/iphone-light-table/

It's easy to integrate this code in your project. just open the HTML source, copy the Javascript, and change the init() function regarding your needs.

Samuel Michelot
Reloading does not work for resetting the zoom in my case. Do I need to add something e.g. to the script to make it reset due to reloading?
JanD
No, this code window.location.reload(); should reload the web page with the default scale (like the first loading)
Samuel Michelot