jQuery-ui 可拖动在旋转后更改轴

标签 jquery jquery-ui rotation jquery-ui-draggable css-transforms

我创建了this fiddle来展示我的问题。请点击旋转按钮尝试移动黄色框(您可以在点击按钮之前进行操作)。

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

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

代码:

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;}

最佳答案

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

一个可能的解决方法是使用 appendTohelper 选项,如下所示:

<强> Working Example

$(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)'
                });
            }
        });

    });
});

关于jQuery-ui 可拖动在旋转后更改轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18813144/

相关文章:

javascript - 删除 jQuery 中的函数

javascript - 解析和字符串化一个json对象jquery

Javascript 遍历元素并将元素换成 HTML

c++ - 在 DirectX9 中旋转单个对象

iOS 7 在标签栏中旋转 View 时, View 右侧不可点击

javascript - 查找元素的目标

html - 日期时间选择器 : Reset

javascript - 如何为 <img> 标签使用模糊事件

javascript - 如何调整 jQuery UI Accordion 的高度?

Android 布局 View 围绕一个圆圈旋转和间隔?