【问题标题】:jQuery-ui draggable changes axis after rotation旋转后jQuery-ui可拖动更改轴
【发布时间】:2013-09-16 21:57:47
【问题描述】:

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

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

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

代码:

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

【问题讨论】:

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


    【解决方案1】:

    所以这里的问题是 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)'
                    });
                }
            });
    
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-01
      • 2021-08-10
      • 1970-01-01
      相关资源
      最近更新 更多