我正在处理一个页面,它的所有内容都使用 panzoom 进行缩放。问题是当我在页面中拖动某些东西时,拖动项目的位置不好。
问问题
1811 次
2 回答
2
我不确定,但也许我找到了答案。
这里有两点:
- 拖动对象时不要移动背景
- 根据背景比例缩放光标移动
在我的缩放背景代码下方并将对象移动到它上面。根据这个答案缩放光标
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;
});
于 2016-09-16T00:59:32.877 回答
0
给你。我正在使用浏览器js。jquery UI 和 Panzoom 的可拖动性
var viewport = $('.frame');
var $pz = $('.panzoom');
$pz.panzoom({
minScale: .8,
maxScale: 3,
onPan: function() {
// console.log('pan');
},
onStart: function(event) {
// console.log('start', event);
return true;
},
});
$('.item').draggable({
helper: 'clone',
appendTo: '.workspace',
zIndex: 100505,
stop: function(event, ui) {
event.target.remove();
},
});
于 2020-08-11T11:01:27.450 回答