resize.html 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="../dist/hammer.js"></script>
  5. <script src="../dist/svg-pan-zoom.js"></script>
  6. <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  7. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
  8. </head>
  9. <body style="width: 100%; height: 100%">
  10. <h1>Demo for svg-pan-zoom: Resize SVG container on page resize</h1>
  11. <div id="container" style="width: 95%; height: 80%; border:1px solid black; ">
  12. <svg id="demo-tiger" xmlns="http://www.w3.org/2000/svg" style="display: inline; width: 100%; height: 80%; " version="1.1">
  13. <g id="g444" fill="none">
  14. <rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)" />
  15. </g>
  16. </svg>
  17. </div>
  18. <script>
  19. // Don't use window.onLoad like this in production, because it can only listen to one function.
  20. window.onload = function() {
  21. var panZoom = window.panZoom = svgPanZoom('#demo-tiger', {
  22. zoomEnabled: true,
  23. controlIconsEnabled: true,
  24. fit: 1,
  25. center: 1
  26. });
  27. $(window).resize(function(){
  28. panZoom.resize();
  29. panZoom.fit();
  30. panZoom.center();
  31. })
  32. };
  33. </script>
  34. </body>
  35. </html>