Giter VIP home page Giter VIP logo

panzoom's Introduction

panzoom build status

Extensible, mobile friendly pan and zoom framework (supports DOM and SVG).

Demo

Usage

Grab it from npm and use with your favorite bundler:

npm install panzoom --save

Or download from CDN:

<script src='https://unpkg.com/[email protected]/dist/panzoom.min.js'></script>

If you download from CDN the library will be available under panzoom global name.

Pan and zoom DOM subtree

// just grab a DOM element
var element = document.querySelector('#scene')

// And pass it to panzoom
panzoom(element)

SVG panzoom example

<!-- this is your html file with svg -->
<body>
  <svg>
    <!-- this is the draggable root -->
    <g id='scene'> 
      <circle cx='10' cy='10' r='5' fill='pink'></circle>
    </g>
  </svg>
</body>
// In the browser panzoom is already on the
// window. If you are in common.js world, then 
// var panzoom = require('panzoom')

// grab the DOM SVG element that you want to be draggable/zoomable:
var element = document.getElementById('scene')

// and forward it it to panzoom.
panzoom(element)

If require a dynamic behavior (e.g. you want to make an element not draggable anymore, or even completely delete an SVG element) make sure to call dispose() method:

var instance = panzoom(element)
// do work
// ...
// then at some point you decide you don't need this anymore:
instance.dispose()

This will make sure that all event handlers are cleared and you are not leaking memory

Events notification

The library allows to subscribe to transformation changing events. E.g. when user starts/ends dragging the element, the element will fire panstart/panend events. Here is example of all supported events:

var instance = panzoom(element);
instance.on('panstart', function(e) {
  console.log('Fired when pan is just started ', e);
  // Note: e === instance.
});

instance.on('pan', function(e) {
  console.log('Fired when the `element` is being panned', e);
});

instance.on('panend', function(e) {
  console.log('Fired when pan ended', e);
});

instance.on('zoom', function(e) {
  console.log('Fired when `element` is zoomed', e);
});

instance.on('zoomend', function(e) {
  console.log('Fired when zoom animation ended', e);
});

instance.on('transform', function(e) {
  // This event will be called along with events above.
  console.log('Fired when any transformation has happened', e);
});

See JSFiddle console for a demo.

Ignore mouse wheel

Sometimes zooming interferes with scrolling. If you want to alleviate it you can provide a custom filter, which will allow zooming only when modifier key is down. E.g.

panzoom(element, {
  beforeWheel: function(e) {
    // allow wheel-zoom only if altKey is down. Otherwise - ignore
    var shouldIgnore = !e.altKey;
    return shouldIgnore;
  }
});

See JSFiddle for the demo. The tiger will be zoomable only when Alt key is down.

Ignore mouse down

If you want to disable panning or filter it by pressing a specific key, use the beforeMouseDown() option. E.g.

panzoom(element, {
  beforeMouseDown: function(e) {
    // allow mouse-down panning only if altKey is down. Otherwise - ignore
    var shouldIgnore = !e.altKey;
    return shouldIgnore;
  }
});

Note that it only works when the mouse initiates the panning and would not work for touch initiated events.

Ignore keyboard events

By default, panzoom will listen to keyboard events, so that users can navigate the scene with arrow keys and +, - signs to zoom out. If you don't want this behavior you can pass the filterKey() predicate that returns truthy value to prevent panzoom's default behavior:

panzoom(element, {
  filterKey: function(/* e, dx, dy, dz */) {
    // don't let panzoom handle this event:
    return true;
  }
});

Zoom Speed

You can adjust how fast it zooms, by passing optional zoomSpeed argument:

panzoom(element, {
  zoomSpeed: 0.065 // 6.5% per mouse wheel event
});

Pinch Speed

On touch devices zoom is achieved by "pinching" and depends on distance between two fingers. We try to match the zoom speed with pinch, but if you find that too slow (or fast), you can adjust it:

panzoom(element, {
  pinchSpeed: 2 // zoom two times faster than the distance between fingers
});

Get current transform (scale, offset)

To get the current zoom (scale) level use the getTransform() method:

console.log(instance.getTransform()); // prints {scale: 1.2, x: 10, y: 10}

Fixed transform origin when zooming

By default when you use mouse wheel or pinch to zoom, panzoom uses mouse coordinates to determine the central point of the zooming operation.

If you want to override this behavior and always zoom into center of the screen pass transformOrigin to the options:

panzoom(element, {
  // now all zoom operations will happen based on the center of the screen
  transformOrigin: {x: 0.5, y: 0.5}
});

You specify transformOrigin as a pair of {x, y} coordinates. Here are some examples:

// some of the possible values:
let topLeft = {x: 0, y: 0};
let topRight = {x: 1, y: 0};
let bottomLeft = {x: 0, y: 1};
let bottomRight = {x: 1, y: 1};
let centerCenter = {x: 0.5, y: 0.5};

// now let's use it:
panzoom(element, {
  transformOrigin: centerCenter
});

To get or set new transform origin use the following API:

let instance = panzoom(element, {
  // now all zoom operations will happen based on the center of the screen
  transformOrigin: {x: 0.5, y: 0.5}
});

let origin = instance.getTransformOrigin(); // {x: 0.5, y: 0.5}

instance.setTransformOrigin({x: 0, y: 0}); // now it is topLeft
instance.setTransformOrigin(null); // remove transform origin

Min Max Zoom

You can set min and max zoom, by passing optional minZoom and maxZoom argument:

var instance = panzoom(element, {
  maxZoom: 1,
  minZoom: 0.1
});

You can later get the values using getMinZoom() and getMaxZoom()

assert(instance.getMaxZoom() === 1);
assert(instance.getMinZoom() === 0.1);

Disable Smooth Scroll

You can disable smooth scroll, by passing optional smoothScroll argument:

panzoom(element, {
  smoothScroll: false
});

With this setting the momentum is disabled.

Pause/resume the panzoom

You can pause and resume the panzoom by calling the following methods:

var element = document.getElementById('scene');
var instance = panzoom(element);

instance.isPaused(); //  returns false
instance.pause();    //  Pauses event handling
instance.isPaused(); //  returns true now
instance.resume();   //  Resume panzoom
instance.isPaused(); //  returns false again

Script attachment

If you want to quickly play with panzoom without using javascript, you can configure it via script tag:

<!-- this is your html file -->
<!DOCTYPE html>
<html>
<head>
  <script src='https://unpkg.com/[email protected]/dist/panzoom.min.js'
    query='#scene' name='pz'></script>
</head>
<body>
  <svg>
    <!-- this is the draggable root -->
    <g id='scene'> 
      <circle cx='10' cy='10' r='5' fill='pink'></circle>
    </g>
  </svg>
</body>
</html>

Most importantly, you can see query attribute that points to CSS selector. Once the element is found panzoom is attached to this element. The controller will become available under window.pz name. And you can pass additional options to the panzoom via attributes prefixed with pz-.

Here is a demo: Script based attributes

Adjust Double Click Zoom

You can adjust the double click zoom multiplier, by passing optional zoomDoubleClickSpeed argument.

When double clicking, zoom is multiplied by zoomDoubleClickSpeed, which means that a value of 1 will disable double click zoom completely.

panzoom(element, {
  zoomDoubleClickSpeed: 1, 
});

Set Initial Position And Zoom

You can set the initial position and zoom, by chaining the zoomAbs function with x position, y position and zoom as arguments:

panzoom(element, {
  maxZoom: 1,
  minZoom: 0.1,
  initialX: 300,
  initialY: 500,
  initialZoom: 0.5
});

Handling touch events

The library will handle ontouch events very aggressively, it will preventDefault, and stopPropagation for the touch events inside container. Sometimes this is not a desirable behavior.

If you want to take care about this yourself, you can pass onTouch callback to the options object:

panzoom(element, {
  onTouch: function(e) {
    // `e` - is current touch event.

    return false; // tells the library to not preventDefault.
  }
});

Note: if you don't preventDefault yourself - make sure you test the page behavior on iOS devices. Sometimes this may cause page to bounce undesirably.

Handling double click events

By default panzoom will prevent default action on double click events - this is done to avoid accidental text selection (which is default browser action on double click). If you prefer to allow default action, you can pass onDoubleClick() callback to options. If this callback returns false, then the library will not prevent default action:

panzoom(element, {
  onDoubleClick: function(e) {
    // `e` - is current double click event.

    return false; // tells the library to not preventDefault, and not stop propagation
  }
});

Bounds on Panzoom

By default panzoom will not prevent Image from Panning out of the Container. bounds (boolean) and boundsPadding (number) can be defined so that it doesn't fall out. Default value for boundsPadding is 0.05 .

panzoom(element, {
  bounds: true,
  boundsPadding: 0.1
});

Triggering Pan

To Pan the object using Javascript use moveTo(<number>,<number>) function. It expects x, y value to where to move.

instance.moveTo(0, 0);

To pan in a smooth way use smoothMoveTo(<number>,<number>):

instance.smoothMoveTo(0, 0);

Triggering Zoom

To Zoom the object using Javascript use zoomTo(<number>,<number>,<number>) function. It expects x, y value as coordinates of where to zoom. It also expects the zoom factor as the third argument. If zoom factor is greater than 1, apply zoom IN. If zoom factor is less than 1, apply zoom OUT.

instance.zoomTo(0, 0, 2);

To zoom in a smooth way use smoothZoom(<number>,<number>,<number>):

instance.smoothZoom(0, 0, 0.5);

Custom UI to trigger zoom

One of the common use case is to have a custom UI to trigger zoom. For example, you can use a button to zoom in/out. Since this library does not depend on any popular framework (react, vue, etc.) you can implement it yourself following this example:

license

MIT

panzoom's People

Contributors

aesyondu avatar anvaka avatar bakuzan avatar danielfvm avatar dotnetcarpenter avatar efeamadasun avatar graphman65 avatar johnrees avatar jonathanlurie avatar keegan-lillo avatar kevincannon avatar mgenware avatar mjamro avatar mkrazz avatar moklick avatar niekert avatar odai-alali avatar ralphstodomingo avatar rbonomo avatar santima10 avatar stampyzfanz avatar timo-weike avatar trintragula avatar tuckergordon avatar volcanic-penguin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

panzoom's Issues

Zoom "Step"

Is there a way to set a zoom "Step"?

e.g. { zoomStep: 0.1 } // 10% zoom steps.

Is there a way to disable scaling for childelements?

I would like to use this library as a map with markers. When a marker is clicked it should open a popup container on this specific position which doesn't scale and reposition when zooming or panning, keeping the content readable at all times.

Option to enabled/disable pan zoom

This library has made my job easier. I would like to see option or function to enable/disable pan and or zoom.
Right now the only way to achieve is to dispose() and recreate;

what does this error "ui element is required to be within the scene" mean?

I am getting the above mentioned error with centerOn() function, what am I supposed to pass to it?

this is my HTML structure

<div class="faqdesigner-container">
    <div class="faqdesigner">
        <div class="faqstart"></div>
        <div class="faqnode"></div>
        <svg class="connector"></svg>
        <div class="label-overlay"></div>
        <div class="faqend"></div>
    </div>
</div>

and this is my pan zoom initializer

function initPanzoom() {
    // just grab any DOM element
    var area = document.querySelector('.faqdesigner');

    var x = $('.faqdesigner-container').width() / 2;
    var y = $('.faqdesigner-container').height() / 2;

    // And pass it to panzoom
    var panzoomInstance = panzoom(area, {
        zoomDoubleClickSpeed: 1
    });

    panzoomInstance.moveTo(x, y);
}

To centerOn() I tried sending div (.faqnode) and svg (.connector) as argument

I am using this plugin for a flow designer, and I want to show flow in the center of the screen during page load, I tried doing that using zoomAbs() and moveTo() but no luck

so I thought centerOn() will be helpful, to just center to the starting node in the diagram

please help on how I can achieve this?

panzoom support object?

Sorry for my bad english...

Good day, I try use this awesome solution for my svg map in page.
But my map is not inline svg, I attach to index.html how object
Here is code of my html

All running fun, but I can pan and zoom only when my cursor on body zone, e.g. if cursor on svg, I can't pan and zoom

<html>
<head>
  <style type="text/css">  
    body,html {
      margin: 0;
      padding: 0;
      position: fixed;
      width: 100%;
      height: 100%;
      background: green;
    }   
    .map {
      width: 50%;
      height: 50%;
    }                                                                               	
  </style>
</head>

<body>
  <object type="image/svg+xml" data="svg/map.svg" width="100%" height="100%" class="map" id="zoomable"</object>

  <script src='js/panzoom.js'></script>
  <script>
    var area = document.getElementById('zoomable')
    panzoom(area)
  </script>
</body>

</html>

Where is my mistake?

zoomToAnimation?

Hi anvaka. Thank you for the great package.

I'm noticing references to 'zoomToAnimation' within the source (

panzoom/index.js

Lines 643 to 661 in 2f5602a

zoomToAnimation = animate(from, to, {
step: function(v) {
zoomAbs(clientX, clientY, v.scale)
}
})
}
function publicZoomTo(clientX, clientY, scaleMultiplier) {
smoothScroll.cancel()
cancelZoomAnimation()
return zoomByRatio(clientX, clientY, scaleMultiplier)
}
function cancelZoomAnimation() {
if (zoomToAnimation) {
zoomToAnimation.cancel()
zoomToAnimation = null
}
}
) but am not sure how to use it, or if it should be working at this point.

Any insight would be great. What i'm hoping to achieve is the ability to animate (vs jumping without a transition) as I set a new zoom value (in addition to new posY and posX values). Possible? or not yet?

Thank you

multi finger pan

Currently the library either pans if there's a single-finger touch, or zooms when there's a 2 finger touch.

Looking at how most native pan/zoom applications (e.g. google maps) work, then you can see that usually these actions are not mutually exclusive. E.g. you can pan while zooming, where you'd pan the average vector of both fingers. This not only feels more natural, but together with #40 it would also open new use cases of for example having drag drop inside a panzoom region (drag drop handled by single-finger touches and panzoom by two-finger touches).

I could make a PR for this if you'd agree with this.

How to handle touch events?

I can't figure out how to get touch events (using the d3.js library) to work.

Is there a way to tell panzoom to not ignore touch events?

Setting an initial zoom

Would be nice to be able to set an initial transform value on the scene:

panzoom(document.getElementById('g4'), {
    initialZoom: 2
});

Disable momentum?

Hello. When I let go of the mouse key after dragging, the panzoom'ed object would move some residual distance. This is extremely undesired and frustrating.

I see there is no option to disable it. Probably moveByAnimation.cancel() inside panend listener would help, if only it were exposed on the module, which it isn't. Maybe amator.sharedScheduler.clearAll()? No idea how to access it from imported panzoom.js, either.

Currently I have to do
for (var i = 1; i < 99999; i++) window.cancelAnimationFrame(i);

Drag using 2 fingers

When I drag using two fingers :

  • Google maps moves the map
  • Panzoom zoom into the map (I have to put 3 fingers to move on the map)

How to move using 2 fingers (not 3 fingers) with panzoom?

Mobile users

Hi I have noticed that the pan zoom does not allow for links to be opened on mobile. Just a heads up.

How to always zoom from center?

In examples you have provided, I've noticed that (percieved?) transform-origin for the zoom is based of current cursor position. Would it be possible to force the transform-origin to always be set on center center?

I've tried to look around your code, even play with some variables, but unfortunately I wasn't able to find where this is determined. Thanks in advance!

Android Webview Pause/Resume not working properly in combination with InteractJS

_This applies for both Android and iOS webviews with scroll disabled. Code is adapted for android only though. _

I'm trying to make an element draggable and when it's being dragged, I pause panzoom. When I release, I want to resume Panzoom. However:

Using resume() does not re-enable zooming. Re-initialization does enable zooming again but I would prefer a resume() to be working.

Steps to reproduce:
0. Host following html file

  1. Open chrome on an android phone.
  2. Zoom on the yellowish rectangle.
  3. Slide the blue bar horizontally (Pausing the zoom)
  4. Zoom for 4 seconds. (Zoom not working)
  5. (Reinitialization hits and zoom resumes to work)

https://jsfiddle.net/kgx65p8s/2/

<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, user-scalable=no" />
</head>

<body>
  <div id="container">
    <style>
      #drag-me::before {
        content: "#"attr(id);
        font-weight: bold;
      }

      svg {
        background-color: wheat;
        width: 300px;
        height: 300px;
      }
    </style>
    <div id="interact-canvas">
      <svg id="svg-canvas">
        <rect class="rect" width="200" height="100" fill="blue" />
      </svg>
    </div>
  </div>


  <script src="https://unpkg.com/[email protected]/dist/interact.min.js"></script>
  <script src='https://cdn.rawgit.com/anvaka/panzoom/v6.1.3/dist/panzoom.min.js'></script>
  <script>
    var controller;
    window.onload = function (e) {
      controller = panzoom(document.getElementById('container'), {

      });
      document.getElementById("svg-canvas").addEventListener("touchmove",
        function (event) {
          //disable native pan
          if (event.touches[0].target.classList.contains("rect")) {
            if (event.preventDefault) event.preventDefault();
            event.stopPropagation();
          }
        }, true);
    };
  </script>
  <script>
    interact('.rect')
      .draggable({
        onmove: dragMoveListener,
        onstart: function () {
          console.log("start drag")
          controller.pause();
        },
        onend: function () {
          console.log("stop drag")
          controller.resume(); //FAILS, does not re-enable zoom

          //reinit works, but it's ugly.
          setTimeout(function () { controller = panzoom(document.getElementById('container'), {}) }, 5000);
        }
      });

    function dragMoveListener(event) {
      console.log("drag move")
      var target = event.target,
        x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx;
      target.style.webkitTransform =
        target.style.transform =
        'translate(' + x + 'px)';
      target.setAttribute('data-x', x);
    }
  </script>
</body>

</html>

How to set bounds params

Hi:

There doesn't seem to be any documentation on how to set a bounding conatiner for the panning.
I would love to just have it pan within the parent element. Is there a way to do this?

I tried to look through the library. This is what I guessed would be the way set the bounds, but it didn't work

bound: {
top:0,
bottom:100,
left:100,
right:100,
}

This would be very helpful if you could inform me.
Thanks!

Is it possible to configure and modifier key for the zoom / pan ?

Really cool library, worked smoothly out of the box !! And the SVG keeps all its interactivity.

Usually zooming interferes with scrolling so often people use a modifier key like shift or option for the zoom / pan operation.

Would it be possible to add that to the panzoom call as an optional config?

feature request: zoom to fit

greetings. thx for the great lib. i see that you offer .zoomAbs(...), but my content is unknown ahead of time. how would you feel about offering a .fit() method that zoomed in/out to fit the panzoom content to the content container?

thanks!

Boundaries

Hi!
I'm fairly new to all this, so this might not be a real issue.

When using this library, I've found that the element I want to pan/zoom is draggable all around the page. Basically, I would need it to only be draggable inside a certain part of my page, like it's parent div. I don't mind the image to be able to go outside of its borders, but not over other things in the page (so that what goes outside is just not visible).

I've solved it with an iframe right now, so my svg is only draggable within that body, however I would prefer not using iframes. Are there other options?

Thanks in advance.

Handles and filters

Hi,

I am trying to use jQuery UI's draggable inside body (or a div) which is given as a parameter to panzoom(),
when I try to drag (the draggable elements), the whole div moves - is there a way to filter specific elements (inside the parent div) from triggering pan/zoom?

Zoom location center wrong if zoomable element not top on page

I go the the Regular DOM Object demo
I edit the HTML in page, add a div and make it tall

break zoom

above the ".zoomable" div

zoom center not correct anymore for Y. X still lines up nicely.

Normally I have to adjust ClientY with pageY or offset.

Anybody else got this?

Bounds

Hi!
Is there a way to set bounds to the panzoom component?

Lets say I have an inner document that is draggable. When I drag it out, I want to set boundaries to it so it don't come off the "inner document".

screen shot 2018-10-31 at 4 47 25 pm

My inner document is over the toolbar. Is there a way to block it?

How to disable key listeners on panzoom?

Mb some1 can point me is it possible to disable some or all key listeners. When pan zoom once activated his key listeners interfere with native listeners (as moving right-left and up-down with arrow keys for example)

Buttons

I would like to add buttons for reset, zoom in, zoom out. With javascript, how would that work or any ideas?

use strict string

Please add 'use strict'; string in the top of the index.js file, because old browsers doesn't support few methods of syntax

Ger current zoom scale

Just curious, is this the best way to get the current zoom scale? I want to hide/show elements based on zoom level.

document.body.addEventListener('zoom', function(e) {
        var map = document.getElementById("tick-map").children[0];
        var zoomLevel = map.style.transform.split(',')[0].replace("matrix(","");
}, true);

use of 'let' breaks uglifyjs

I'm getting the build error

ERROR in index.js from UglifyJs
Unexpected token: name (clientRect) [./node_modules/panzoom/index.js:146,0][index.js:57353,8]

caused by line 146:

let clientRect = owner.getBoundingClientRect()

since the rest of the module is es5, I believe it should be 'var clientRect...' ?

initial zoom and position do not work

when I use the default position and scale function the way it is described, it only changes the default y position but nothing else. additionally, the yposition isnt even what I set it to. when I use .zoomAbs(300,500,0.2); it sets the default matrix to: matrix(1, 0, 0, 1, 0, 400); instead of matrix(0.2, 0, 0, 0.2, 300, 500); like you'd expect. If i change the zoomAbs numbers it the resulting y position changes but that's all

zoom point is not based on top of zoomable region.

https://jsfiddle.net/markarian/wLbocegs/5/

When I add a div full of text above the zoomable region. zoom happens not centered at mouse
point but what seems like distance from top of page. so zoomable region will zoom as if mouse is at top. when it's really at the non zoomable region. See jsfiddle.

I think the zoom point needs to subtract the top of the current div, when the event comes through.

Thanks in advance for look at this.

How can I reset the zoom?

I'd like to reset the zoom size of the element to initial size. Can I know if there is any built-in method provides this functionality. Otherwise, how can I achieve this result?

Thanks in advance

Bug with pause/resume and onselectstart (textSelectionInterceptor)

Hey,

First of all thanks for the great panzoom lib!

However, I think I found a bug with the pause/resume logic. The problem I ran into was that after pausing and resuming my panzoom instance I was no longer able to select any text in my app. This proved to be a problem for us as we use a rich text editor which relied on selection events to work. After some time debugging I found that after I call panzoom.pause(), it sets an event handler on window.document.onselectstart which looks like:

function disabled(e) {
  e.stopPropagation();
  return false;
}

However, after calling panzoom.resume() this disabled method is not removed, meaning text selection events on the entire window no longer work as expected. The default for window.document.onselectstart seems to be null. If I set the value back to null after I call panzoom.resume() everything seems to work as expected again but it feels like a bit of a hacky workaround.

As far as I can track it down in the package this logic happens added in the capture/release methods of the textSelectionInterceptor: https://github.com/anvaka/panzoom/blob/master/lib/textSelectionInterceptor.js
When this line: window.document.onselectstart = prevSelectStart gets executed it seems for some reason to store the disabled method in prevSelectStart.

I think the issue is caused because in our app we use a dragable element inside the panzoom element and it might affect the mouse up/down handlers to which the capture and release methods from textSelectionInterceptor are attached. I'm not 100% sure how to fix this bug (or if it should even be fixed in panzoom or in react-dnd which we use for creating dragable elements) but figured I'd make an issue to at least help people out who might run into this in the future :)

Disable pan and only allow zoom

Is there a way that I can disable pan and only allow zoom? I have my own methods of using pan and I just need the zoom functionality.

Restrict viewport

Hello! Is there a way to restrict the pan to only happen within the element? I don't want to enable users to hide the element.

Confusing behavior onTouch / onBeforeWheel.

Currently there are 2 functions that are called before user interaction is handled:
-onTouch
-beforeWheel

But I find the API of these confusing, since onTouch is only meant to return 'false' if you want to propagate the touches, while onBeforeWheel is only meant to return 'true' if you don't want the library to handle the event.

I'd propose to unify these and extend them to each of these listeners:
-beforeTouch
-beforeWheel
-beforeMouseDown
-beforeDoubleClick
-beforeKeyDown

Each of these could then return: { ignore: boolean, propagate: boolean }.
This would also make it easier to for example allow drag/drop within the panzoom region.

I could make a PR for this, but since it'd mean a breaking change I'd rather get your thoughts on this first.

panzoom prevents developer's double click events in the app

First of all thanks for making such a great plugin!

The following is the code I am using,

        // just grab any DOM element
        var area = document.querySelector('.faqdesigner');

        // And pass it to panzoom
        panzoom(area, {
            zoomDoubleClickSpeed: 1
        });

        // this is the double click event
        $('.appcontainer').on('dblclick', '.faqnode', onNodeDblClick);

but double click on elements is not firing because of panzoom plugin, so I investigated and checked the source code, I see a lot of

e.preventDefault();
e.stopPropagation();

even inside function onDoubleClick(e) { ... } which I commented and my double click event gets fired

it is restricting and interfering with the developers code, it may be nice to have it configurable like switch on or off through plugin settings

could you please have a look

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.