Jquery UI 可拖动和可调整大小不起作用

标签 jquery jquery-ui

我正在尝试通过以下 fiddle 实现效果:

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

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

如何让 div 既可拖动又可调整大小? contenteditable="true"的 div 不起作用,无法编辑。这里有什么问题?

更新了代码 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>

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

最佳答案

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

<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/cupertino/jquery-ui.css" />

然后您也许可以将 draggableressized 元素合并为一个,并通过 class 进行引用。

HTML

<div id="background">
    <div class="draggable resizeable" style="display:inline-block">
        <div contenteditable="true" id="message">
            Enter message..
        </div>
    </div>
</div>

JQUERY

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

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

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

关于Jquery UI 可拖动和可调整大小不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13467550/

相关文章:

javascript - HTML 进度元素未更新

javascript - JS Slide 切换侧边栏并展开内容 div

jQueryUI 自动完成功能不适用于对话框和 zIndex

Jquery UI slider 工具提示类

jquery-ui - jQuery UI 多个日期选择器 : set individual event by id after setting options by class

jquery:可拖动插件 -> 从 html5 视频控件中删除拖动行为?

javascript - jQueryeach();生成 html 元素仅返回最后一个值

jquery - 在 jQuery 中,选择器或等效函数哪个更快,或者取决于什么?

javascript - 无法配置 jQuery 日期选择器来选择默认日期

javascript - jquery ui可与angularjs排序,如何防止水平拖放?轴 :y not working