【问题标题】:Jquery UI .draggable and ChromeJquery UI .draggable 和 Chrome
【发布时间】:2014-09-24 20:10:43
【问题描述】:

我在玩 JqueryUI,在 chrome 中打开页面时遇到了这个问题。

这是页面的 HTML

<div class="main">
        <div class="container">
            <div class="jqui">
                <div class="contentTitle">
                    <h1>Playground</h1>
                </div>
                <div class="content">
                    <div id="draggable" class="ui-widget-content colored">1                            
                    </div>
                    <div id="draggable1" class="ui-widget-content colored">2                            
                    </div>
                    <div class="dragcontainer">
                        <div id="draggable2" class="ui-widget-content colored">3
                        </div>
                    </div>
            </div><!--jqui End-->  
        </div><!--Container End-->                      
    </div><!--Main End-->

您可以找到完整代码here

在 Firefox 中,粉红色背景容器中的可拖动框工作正常,但是当我在 Chrome 中打开时,它只是上下颠倒拖动,并且似乎将框的宽度作为容器的宽度。我我在这里做错了什么?感谢您的帮助。

谢谢。

【问题讨论】:

    标签: javascript jquery html css jquery-ui


    【解决方案1】:

    试试这个解决方案:

    HTML

    <div class="dragcontainer">
        <div style="position: absolute; left: 50%;">
            <div id="draggable2" style="position:relative;left: -50%;" class="ui-widget-content colored">3</div>
        </div>
    </div>
    

    JQuery

    $(function () {
        $("#draggable").draggable();
        $("#draggable1").draggable({
            revert: true
        });
        $("#draggable2").draggable({
            containment: ".dragcontainer",
            revert: true
        });
    });
    

    DEMO

    【讨论】:

    • 感谢您的回复,但如果您在谷歌浏览器中查看,问题就是这样。
    • @Suraj Verma,好的,看看我的回答。
    • 再次感谢,我之前也尝试过,我希望它只对齐中心,因为它在 Firefox 中工作,它在 Chrome 中也应该可以正常工作,如果你能建议我,我很感激,如果我遗漏了什么。
    • 有一个为你的 bug 编辑过的 css。Draggable:在 Chrome 和 IE8 中可以拉出可拖动对象bugs.jqueryui.com/ticket/7016
    【解决方案2】:

    我已经修改了如下代码,它在 chrome 中运行:

    $(function(){
    
        $("#draggable").draggable();
    
        $("#draggable1").draggable({revert:true});
    
        $("#draggable2").draggable({revert:true});
    
    });
    

    为什么要添加containment:".dragcontainer"

    【讨论】:

    猜你喜欢
    • 2012-03-23
    • 2011-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    • 2017-10-29
    • 2021-02-10
    相关资源
    最近更新 更多