एक साथ अंतर खींचने योग्य कि बदलने पर नहीं है तत्व खुद, लेकिन माता-पिता पर। तो यह थोड़ा तर्क बदलता है।
यहां इस विशिष्ट मामले का समाधान है, लेकिन आप देखेंगे कि स्थिति के आधार पर यह बदल सकता है। उदाहरण के लिए, यदि आप ट्रांसफॉर्म-मूल बदलते हैं, या यदि आपके पास क्षैतिज क्रमबद्ध है, तो इसे अनुकूलित करना होगा। लेकिन तर्क ही रहता है:
var zoomScale = 0.5;
$(".container")
.sortable({
sort: function(e, ui) {
console.log(ui.position.left)
var changeLeft = ui.position.left - ui.originalPosition.left;
// For left position, the problem here is not only the scaling,
// but the transform origin. Since the position is dynamic
// the left coordinate you get from ui.position is not the one
// used by transform origin. You need to adjust so that
// it stays "0", this way the transform will replace it properly
var newLeft = ui.originalPosition.left + changeLeft/zoomScale - ui.item.parent().offset().left;
// For top, it's simpler. Since origin is top,
// no need to adjust the offset. Simply undo the correction
// on the position that transform is doing so that
// it stays with the mouse position
var newTop = ui.position.top/zoomScale;
ui.helper.css({
left: newLeft,
top: newTop
});
}
});
http://jsfiddle.net/aL4ntzsh/5/
संपादित करें:
पिछला जवाब स्थिति के लिए काम करेंगे, लेकिन के रूप में सभ्य प्रेमी द्वारा बताया, वहाँ चौराहे समारोह है कि जब सत्यापित करता है के साथ एक दोष है एक सॉर्टिंग होना चाहिए। असल में, पदों की सही गणना की जाती है, लेकिन आइटम चौड़ाई और ऊंचाई मान जो परिवर्तित नहीं होते हैं, जो समस्या पैदा कर रहे हैं। आप खाते में स्केल फैक्टर लेने के लिए प्रारंभिक ईवेंट पर उन्हें संशोधित करके इन मानों को समायोजित कर सकते हैं। उदाहरण के लिए इस तरह:
start: function(e, ui) {
var items = $(this).data()['ui-sortable'].items;
items.forEach(function(item) {
item.height *= zoomScale;
item.width *= zoomScale;
});
}
http://jsfiddle.net/rgxnup4v/2/
स्रोत
2016-04-18 03:04:57
मैं इस सवाल के लिए एक इनाम शुरू कर दिया।हालांकि मुझे जरूरी नहीं लगता कि यह प्रश्न बड़े दर्शकों के लिए व्यापक रूप से लागू होता है, मैं * एक * कैननिकल उत्तर देखना चाहता हूं जो सॉर्ट करने योग्य ईवेंट हैंडलर में वास्तव में समायोजित करने की आवश्यकता है और क्यों jquery draggable समाधान, सुझाया गया था ओपी के [संदर्भित SO प्रश्न] में (https://stackoverflow.com/q/10212683/165154), jquery sortables पर लागू नहीं है। –