jQuery UI可拖动和可调整大小无法正常工作

Vis*_*mar 5 jquery jquery-ui

我正在尝试通过以下方式来达到效果:

http://jsfiddle.net/vrUgs/2/

检查我的jsfiddle:http : //jsfiddle.net/H9kgP/

我怎样才能使div既可拖动又可调整大小?具有contenteditable =“ true”的div无法正常工作,无法进行编辑。这里有什么问题?

Chris Moutray的Answer中的更新代码:

<!doctype html> 
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>jQuery UI</title>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/cupertino/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
    <style>
    body{ }
    #container{ width: 980px; margin: 0 auto; }
    #background { background: red; width: 600px; height: 400px; margin: 0 auto; background-size: 600px 400px;}
    .draggable { width: 250px; height: 150px; padding: 0.5em; opacity: 0.5; color: #000; background: #f0f0f0; }
    </style>
    <script>
        $(document).ready(function() {
            $(".resizeable").resizable({
                containment: "#background"
            });

            $(".draggable").draggable({
                cursor: "crosshair",
                containment: "#background",
            });
        });

    </script>
</head>
<body>
<div id="container">
    <div id="background">
        <div class="draggable resizeable" style="display:inline-block">
                <div contenteditable="true" id="message">
                    Enter message..
                </div>
        </div>
    </div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

可拖动的文件工作正常,但水平调整大小不起作用。当我尝试增加水平尺寸时,它会自动变小,然后无法再次调整尺寸。可能是什么问题?

Chr*_*ray 3

首先你需要链接 jquery-ui 资源

<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/cupertino/jquery-ui.css" />
Run Code Online (Sandbox Code Playgroud)

然后,您也许可以将可拖动可调整大小的元素合并为一个,并改为按引用。

超文本标记语言

<div id="background">
    <div class="draggable resizeable" style="display:inline-block">
        <div contenteditable="true" id="message">
            Enter message..
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

查询

$(".resizeable").resizable({
    containment: "#background"
});

$(".draggable").draggable({
    cursor: "crosshair",
    containment: "#background",
});
Run Code Online (Sandbox Code Playgroud)

这是代码的工作示例http://jsfiddle.net/chrismoutray/H9kgP/2/