Jquery可以使用panzoom拖动

时间:2015-11-21 05:29:42

标签: jquery jquery.panzoom

我在使用panzoom缩放所有内容的页面。问题是,当我在页面中拖动某些内容时,拖动项目的位置会变差。

2 个答案:

答案 0 :(得分:1)

我不确定,但也许我找到了回答。

这里有两点:

  • 拖动对象时不要移动背景
  • 根据背景比例缩放光标移动

在我的代码下方缩放背景并在其上移动对象。 根据{{​​3}}

缩放光标

HTML

<script src = "/js/vendors/jquery-ui.min.js"></script>
<script src = "/js/vendors/jquery.panzoom.min.js"></script>

<div id = "map-viewport">
    <div id = "map">
        <div class = "draggable">1</div>
        <div class = "draggable">2</div>
    </div>
</div>

JS

var map = $('#map');
var viewport = $('#map-viewport');

map.panzoom({
    increment: 0.1,
    minScale: 1,
    contain: 'invert'
});

viewport.on('wheel', function( e ) {
    e.preventDefault();
    var delta = e.delta || e.originalEvent.wheelDelta;
    var zoomOut = delta ? delta < 0 : e.originalEvent.deltaY > 0;
    map.panzoom('zoom', zoomOut, {
        increment: 0.2,
        animate: false,
        focal: e.originalEvent
    });
});

var click = { x: 0, y: 0};

$('.draggable')
    .draggable({
        containment: 'parent',
        start: function(e) {
            click.x = e.clientX;
            click.y = e.clientY;
        },

        drag: function(e, ui) {
            var m = map.panzoom('getMatrix');
            var zoom = Math.sqrt(m[0] * m[3]); // zoom don't change proportion and scale 
            var original = ui.originalPosition;

            ui.position = {
                left: (e.clientX - click.x + original.left) / zoom,
                top:  (e.clientY - click.y + original.top ) / zoom
            };
        }
    })
    .on('mousedown', function(e){ 
        e.stopImmediatePropagation(); 
        return false;
    });

答案 1 :(得分:0)

在这里。我正在使用浏览器js。 jQuery UI和Panzoom的可拖动

codepen link

CREATE TABLE T1 (
       id INTEGER PRIMARY KEY,
       [Other columns]
);

CREATE TABLE T2 (
       carId INTEGER REFERENCES T1(id),
       imperfection INTEGER
);