1
下面的代码:jQuery的可拖动appendTo不起作用
jQuery的
$('.dragBox').draggable({
axis: 'y',
appendTo: 'parent',
containment: [0,0,0,150],
start: function() {
$(this).addClass('grabbing');
},
stop: function() {
$(this).removeClass('grabbing');
}
});
HTML
<div class="container">
<div class="cropBox"><div class="dragBox"></div></div>
</div>
但.dragBox不追加到.cropBox。 内框的y轴不从0开始,从-117开始。 117是.cropBox和窗口顶边之间的像素距离。
编辑
我固定它
startDrag();
$(window).resize(function(){
startDrag();
});
function startDrag(){
var xAxis = $('.dragBox').outerWidth() - $('.cropBox img').outerWidth();
var yAxis = $('.dragBox').outerHeight() - $('.cropBox img').outerHeight();
var x1 = $('.dragBox').position().left;
var y1 = $('.dragBox').position().top;
if($('.dragBox img').outerWidth() > $('.dragBox img').outerHeight()) {
var axis = 'x';
var containment = [xAxis+x1,0,x1,0];
} else {
var axis = 'y';
var containment = [0,yAxis+y1,0,y1];
}
$('.dragBox img').draggable({
axis: axis,
appendTo: 'parent',
containment: containment,
start: function() {
$(this).addClass('grabbing');
},
stop: function() {
$(this).removeClass('grabbing');
}
});
}
谢谢回复!
你试过appendTo(“裁剪框”。) – blackhawk 2013-04-04 13:00:01
如果我记得没错的appenTo选项仅用于辅助和无关请使用可拖动元素本身。是的,我想我遇到了同样的问题,帮助者处于错误的位置。 – ggzone 2013-04-04 13:03:27
@blachawk是的,我已经尝试过。 – 2013-04-04 13:17:48