0
A
回答
0
對不起,這不是越早回答。我相信你必須手動檢查元素上,下,左,右邊緣的位置,所以這裏是我做過什麼:
//Call this function from within your .on('dragmove') method.
//It should replace your translations.
function noOverlap(event, overlapElements){
//just for flagging when the target would overlap another element
var overlap = false;
var targetDims = event.target.getBoundingClientRect();
for(i = 0; i < overlapElements.length; i++){
var overlapElementDims =
overlapElements[i].getBoundingClientRect();
//make sure the element doesn't look at itself..
if(overlapElements[i] != event.target){
//checks if the target "doesn't" overlap
if(((targetDims.right + dx) < (overlapElementDims.left + 1))
||((targetDims.left + 1 + dx) > (overlapElementDims.right))
||((targetDims.top + 1 + dy) > (overlapElementDims.bottom))
||((targetDims.bottom + dy) < (overlapElementDims.top + 1))}{
//Basically, the target element doesn't overlap the current
//element in the HTMLCollection, do nothing and go to the
//next iterate
}
else{
//This is if the target element would overlap the current element
//set overlap to true and break out of the for loop to conserve time.
overlap = true;
break;
}
}
};
if(overlap === false){
//if there's no overlap, do your normal stuff, like:
event.target.x += dx;
event.target.y += dy;
event.target.style.webkitTransform =
event.target.style.transform =
'translate(' + event.target.x + 'px, ' + event.target.y + 'px)';
//then reset dx and dy
dy = 0;
dx = 0;
}
else{
if(event.interaction.pointers[event.interaction.pointers.length - 1].type
=== "pointerup"){
//check if the target "is" in the restriction zone
var restriction =
interact(event.target).options.drag.restrict.restriction;
var restrictionDims = restriction.getBoundingClientRect();
if((targetDims.right > restrictionDims.right) ||
(targetDims.left < restrictionDims.left) ||
(targetDims.bottom > restrictionDims.bottom) ||
(targetDims.top < restrictionDims.top)){
event.target.style.webkitTransform =
event.target.style.transform =
'translate(0px, 0px)';
//then reset dx and dy
dy = 0;
dx = 0;
//then reset x and y
event.target.x = 0;
event.target.y = 0;
}
}
}
}
相關問題
- 1. 拖動interact.JS
- 2. 如何將可拖動元素限制爲特定元素
- 3. 如何防止html中可拖動元素的重疊
- 4. 限制jQuery可拖動項目重疊/與同級元素碰撞
- 5. interact.js拖動項目移動在頂部
- 6. Raphael-拖放時檢測重疊元素
- 7. 如何控制重疊元素android活動的繪製順序?
- 8. 將拖放區域限制爲一些可拖動的元素
- 9. 如何獲得元素的ID,而我拖動「拖動」元素
- 10. 如何防止帶拖曳功能的ap元素重疊?
- 11. 如何限制可拖拽列表中元素的數量?
- 12. 在jquery中拖動元素
- 13. 如何在qml中拖動時複製元素的實例?
- 14. 如何在jQuery UI中獲取拖動元素的子元素
- 15. 滾動視圖中的重疊元素
- 16. 使用interact.js拖放功能
- 17. interact.js拖/放引用格
- 18. 重疊元素中的目標元素
- 19. 如何在另一個元素上重疊一個元素
- 20. HTML元素重疊
- 21. 重疊CSS元素
- 22. HTML元素重疊
- 23. 重疊HTML元素
- 24. Div重疊元素
- 25. 如何製作可拖動疊加層的Google地圖/在Android中拖動它?
- 26. 限制在UI元素中
- 27. 同位素元素重疊
- 28. 在css:hover中拖動變換後的Interact.js不再工作
- 29. 限制容器內的可拖動元素
- 30. HTML&jQuery - 需要重疊重疊元素
另外,如果有人結束了讀這篇文章,請讓我知道什麼我所能做的就是提高效率。 – KirklandBrown373
我已經停止通過更新拖動元素的位置拖動,但任何想法如何我可以停止在這種情況下移動鼠標指針? – not2savvy
停止移動鼠標指針是與js交互的完全不同的主題。我會看看這樣的:http://www.smartjava.org/content/html5-use-pointer-lock-api-restrict-mouse-movement-element – KirklandBrown373