Pinch zooming in exported document

Maybe this question was asked in another thread. Is it possible to make a hype document where the user can pinch and zoom on certain parts of the image just like in other iPad app.

Hi Marts,

to activate a pinchZoom on an element run

var scale = 1, newScale, el = hypeDocument.getElementById("yourId");

function saveChanges() {
scale = newScale;

function getScale(e) {
newScale = scale * e.scale;
if(newScale < 1)newScale = 1;
hypeDocument.setElementProperty(el, 'scaleX', newScale);
hypeDocument.setElementProperty(el, 'scaleY', newScale);

el.addEventListener("gesturechange", getScale, false);
el.addEventListener("gestureend", saveChanges, false);

fyi this’ll work on mobilesafari. for intigration on other browsers / devices you’re better off using a library like hammer or quo …


Is it possible to activate a pinch zoom for a complete scene?

Martin Pilon

sure, change

* hypeDocument.currentSceneElement 1.1
* @return {HTMLDivElement} gives you the current scene element
hypeDocument.currentSceneElement = function(){
    return document.querySelector('#'+this.documentId()+' > .HYPE_scene[style*="block"]');

var scale = 1, newScale, el = hypeDocument.currentSceneElement();

Hi @h_classen
Thanks for the code but where (and how) do I implement it ?

Ok and where do I put that code?

Martin Pilon

well, the first version on any behaviour and the second would be fine onSceneload :slight_smile:

Hello @h_classen,
Any idea on how to implement this on a behavior ? I forgot how to do it

Hello @kerguelen,

go to the Actions Inspector or Scene Inspector, choose your favorite behaviour, select run js, paste the code … :slight_smile:

It works !
Also managed to constraint zoom between scale 1 and 2
Any idea how to do this :
1- when pinch/scale, disable every other touch action on the screen
2- pan scaled image

nothing will happen until you pinchzoom the element

Good news ! I also discovered that you can change the center of the scaling action by cmd+click
For exemple, if this point upper-left corner of the image, up and left sides of the image will remain in place and scale will spread to the right-bottm sides

1 Like

And I put that in on every scene?

Yes, or have a Look in The Dokumentation. You will find a Description for some global hypeevents … e.g onsceneload

Did it. Still doesn’t work on the ipad. I’m working to create an app for the iPad.

should work iOS-safari and webview too …

Do you want to see my hype file?

Hello? Would you like to see my hype file to see if I have implemented the code at the right place?

Go ahead and send – the only thing you would need to do to allow user scaling using ‘pinch + zoom’ is to make sure you have these settings setup in the head of your document.

If your document is embedded elsewhere (you said you’re making an app), you might not be able to utilize the pinch + zoom natural behavior that you can get as a regular website. Just make sure that the HTML page has this at the top:

<meta name="viewport" content="user-scalable=yes, width=600" />

how do you want me to send it it is quite large actually. Do you have an email I could use for a wetransfer