mobile - How to avoid svg disappearing while zooming and panning? -
i trying build zoomable map mobile devices of hammer.js: http://www.informatik.uni-bremen.de/~hhappe/visuhappe/svgpan.html (try out in opera on mobile device). recreating following example svg file, embed img-tags: https://github.com/eightmedia/hammer.js/blob/master/examples/pinchzoom.html
while example working jpg file, in case svg (mapgartendeck.svg) disappears partially after first touch-gesture on mobile device (unfortunately, works in opera @ far.. don´t know why). svg boundaries seem shift while panning. tried out embed svg in different ways (object tags , svg tags) nothing solves problem; makes worse , touch not working @ all...
does know how solve problem? essentials code: ...
#pinchzoom { -webkit-transform: translate3d(0,0,0); overflow: hidden; }
... in body:
<div id="pinchzoom" align="center"> <img id="thesvgelement" src="mapgartendeck.svg" alt="" width="639.86" height="400.12" viewport="-639.86 -400.12 639.855 400.117"> <!-- /*try out other ways embed svg:*/ <iframe height="450px" width="95%" src="mapgartendeck.svg" scrolling="no"> <img id="thesvgelement" src="mapgartendeck.png" alt="mapgartendeck.png" width="689px" height="430.95px" left:"2.5px" /> </iframe> <object id="thesvgelement" data="mapgartendeck.svg" type="image/svg+xml" width="95%" left="2.5px" style="display:block"></object> --> </div>
...
<script> var hammertime = hammer(document.getelementbyid('pinchzoom'), { transform_always_block: true, transform_min_scale: 1, drag_block_horizontal: true, drag_block_vertical: true, drag_min_distance: 0 }); var svg = document.getelementbyid('thesvgelement'); var posx=0, posy=0, lastposx=0, lastposy=0, scale=1, last_scale, rotation= 1, last_rotation, dt=0; hammertime.on('touch drag transform dragend doubletap', function(ev) { switch(ev.type) { //rotate should left out case 'touch': last_scale = scale; //last_rotation = rotation; break; case 'drag': if(scale > 1){ posx = ev.gesture.deltax + lastposx; posy = ev.gesture.deltay + lastposy; } break; case 'transform': //rotation = last_rotation + ev.gesture.rotation; scale = math.max(1, math.min(last_scale * ev.gesture.scale, 10)); break; case 'dragend': lastposx = posx; lastposy = posy; break; case 'doubletap': if (dt == 0){ dt=1; scale = 2; }else if (dt ==1){ dt = 0; scale = 1; posx=0; posy=0; }last_scale = scale; //last_rotation = rotation; break; } // transform! var transform = "translate3d("+posx+"px,"+posy+"px, 0) " + "scale3d("+scale+","+scale+", 0) "; //+ "rotate("+rotation+"deg) "; thesvgelement.style.transform = transform; thesvgelement.style.otransform = transform; thesvgelement.style.mstransform = transform; thesvgelement.style.moztransform = transform; thesvgelement.style.webkittransform = transform; });
Comments
Post a Comment