layers.html 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="../dist/svg-pan-zoom.js"></script>
  5. </head>
  6. <body>
  7. <h1>Demo for svg-pan-zoom: Zooming just one SVG layer</h1>
  8. <div id="container" style="width: 300px; height: 500px; border:1px solid black; ">
  9. <svg id="svg-1" xmlns="http://www.w3.org/2000/svg" style="display: inline; width: inherit; min-width: inherit; max-width: inherit; height: inherit; min-height: inherit; max-height: inherit;" version="1.1">
  10. <defs>
  11. <linearGradient id="linear-gradient" x1="0%" y1="0%" x2="0%" y2="100%">
  12. <stop offset="0%" style="stop-color:rgb(56,121,217);stop-opacity:1" />
  13. <stop offset="100%" style="stop-color:rgb(138,192,7);stop-opacity:1" />
  14. </linearGradient>
  15. </defs>
  16. <g stroke="#000">
  17. <rect x="0" y="400" width="100" height="100" fill="yellow"/>
  18. </g>
  19. <g fill="none" class="svg-pan-zoom_viewport">
  20. <g stroke="#000" fill="#FFF">
  21. <rect x="5" y="5" width="240" height="240" fill="url(#linear-gradient)"/>
  22. <path d="M 5 5 L 245 245 Z"/>
  23. </g>
  24. </g>
  25. <g stroke="#000">
  26. <rect x="0" y="0" width="100" height="100" fill="pink"/>
  27. </g>
  28. </svg>
  29. </div>
  30. <script>
  31. // Don't use window.onLoad like this in production, because it can only listen to one function.
  32. window.onload = function() {
  33. // Expose to window namespase for testing purposes
  34. window.panZoomInstance = svgPanZoom('#svg-1', {
  35. viewportSelector: '.svg-pan-zoom_viewport',
  36. zoomEnabled: true,
  37. controlIconsEnabled: true,
  38. fit: true,
  39. center: true,
  40. minZoom: 0.1,
  41. eventsListenerElement: document.querySelector('#svg-1 .svg-pan-zoom_viewport')
  42. });
  43. };
  44. </script>
  45. </body>
  46. </html>