开发者

Webkit iPhone App : How to dynamically change the user zoom (or scale, pich & zoom) in the viewport?

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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜