我有一個與綠色動畫相關的問題,但也可能是一個更普遍的JS問題,因爲我需要在殺死第一個可拖動實例後將mousedown事件轉移到第二個可拖動實例。greensock draggable/triggering點擊並拖動
該codepen希望將說明我在做什麼..代碼是在下面。
Codepen網址:http://codepen.io/anon/pen/ypdGn
var detachdraggable;
var rotatedraggable;
function makeRotateDraggable() {
// create rotate draggable for the cards..
rotatedraggable = Draggable.create(".dragclone", {
type:"rotation",
throwProps:true,
dragResistance : 0,
edgeResistance : 1,
bounds:{minRotation:-60, maxRotation:60},
onDragStart : function() {
var $el = $(this.target);
var cardStartAngle = $el.data('startangle');
},
onDrag: function() {
currentCardAngle = this.rotation;
var $el = $(this.target);
var cardStartAngle = $el.data('startangle');
cardDirection = (currentCardAngle > cardStartAngle) ? "up":"down";
cardTravelDegrees = Math.abs(currentCardAngle - cardStartAngle);
this.vars.type = "x";
},
onDragEnd: function() {
},
onClick: function() {
return false;
}
});
$('.dragclone').mousedown(function() {
$('.dragclone').css('z-index','10');
rotatedraggable[0].enable();
});
$('.dragclone').mouseout(function() {
detachdraggable[0].disable();
$('.dragclone').trigger('mousedown');
});
$('.dragclone').trigger('mouseout');
}
// first setup the x,y draggable..
detachdraggable = Draggable.create('.dragclone', {
type: "x,y",
edgeResistance:1,
throwProps:true,
onPress:function() {
startX = this.x;
startY = this.y;
},
onDrag:function() {
var xChange = this.x - startX,
yChange = this.y - startY,
ratio = Math.abs(xChange/yChange),
direction = [];
// NB:: you can adjust these ratio thresholds to make things
// more or less sensitive to diagonal movement.
if (ratio > 0.25) {
direction.push((xChange < 0) ? "left" : "right");
}
if (ratio < 4) {
direction.push((yChange < 0) ? "up" : "down");
}
if(direction[0] == "left") {
// TweenMax.to($('.cloned'), .0001, {right:-xChange + 135});
}
// moving up so lets switch cards !!
if(direction[0] == "up") {
if(Math.abs(yChange) > 20) {
makeRotateDraggable();
}
}
},
onDragEnd:function() {
// driftDragCardBack();
// if(!cardPopping) { driftClonedCardBack(); }
},
onThrowComplete: function() {
}
});
我爭奪相同的元素2點拖拽元素設置之間進行切換,我想知道如果這是不可能的。基本上,codepen是我想要做的一個例子,但它並不是無縫的。 draggable是爲x,y類型的元素設置的,我想要做的是當拖動方向向上時,取消類型x,y可拖動並切換到類型:旋轉可拖動,以便卡在一個軸上移動。你可以看到我這樣做,但只有當你釋放,然後再次點擊 - 有沒有什麼辦法可以做到這一點無縫,所以它只是中間拖動?
感謝, 賈斯汀
太棒了,謝謝!不能相信我錯過了在文檔中 – user1125489 2014-11-03 10:19:32