2

我创建了这个小提琴来证明我的问题。请单击旋转按钮尝试移动黄色框(您可以在单击按钮之前执行此操作)。

问题很明显 - 在旋转拖放后以一种奇怪的方式工作。

我用谷歌搜索了这个问题,但没有找到解决方案。

编码:

html

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<button id="rotator">rotate</button>

<div id="map">
    <div class="ball">whee</div>
    <div class="ball">heyyy</div>
    <div class="ball">hiii</div>
</div>

js

$(function() {
    $(".ball").draggable();

    $("#rotator").click(function(){    
        $("#map").css({
            WebkitTransform: 'rotate(120deg)',
            '-moz-transform': 'rotate(120deg)'
        });
    });
});

css

.ball {width: 100px; height: 100px; background: yellow; border: 1px solid red;}
#map {margin-top: 50px; border: black 1px solid; min-width: 250px; min-height: 250px;}
4

1 回答 1

2

所以这里的问题是 X 和 Y 轴似乎是面向可拖动的父级的,这看起来很奇怪......

一种可能的解决方法是像这样使用appendToandhelper选项:

工作示例

$(function () {
    $(".ball").draggable({
        appendTo: 'body',
        helper: 'clone'
    });

    $("#rotator").click(function () {
        $("#map").css({
            WebkitTransform: 'rotate(120deg)',
                '-moz-transform': 'rotate(120deg)'
        });

        $(".ball").draggable({
            appendTo: 'body',
            helper: 'clone',
            drag: function () {
                $(".ui-draggable-dragging").css({
                    WebkitTransform: 'rotate(120deg)',
                        '-moz-transform': 'rotate(120deg)'
                });
            }
        });

    });
});
于 2013-09-16T00:38:01.767 回答