首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >jqueryUI可调整大小和可拖动不能一起工作

jqueryUI可调整大小和可拖动不能一起工作
EN

Stack Overflow用户
提问于 2017-12-04 16:03:23
回答 1查看 514关注 0票数 3

当我同时使用jquery-ui resizabledraggable时,我遇到了一个问题。以下是出现问题时的场景:

first move父分区,

然后,调整子分区的大小。

最终子分区显示不正确

如果我去掉了可调整大小的containment选项,效果就没问题了。

我发现选项containment andhelper` `不能同时存在。

谢谢

这是演示

代码语言:javascript
复制
// external js: draggabilly.pkgd.js

$('.father').draggable({
  handle:'.p1'
}).resizable({
      helper: "ui-resizable-helper",
      containment: "parent" 
    });
$('.child').draggable({
  handle:'.p2'
}).resizable({
      helper: "ui-resizable-helper",
      containment: "parent" 
    });
代码语言:javascript
复制
body { font-family: sans-serif; }

.draggable {
  width: 300px;
  height: 300px;
  background: #F90;
  border-radius: 10px;
}
.draggable.is-pointer-down {
  background: #09F;
}
p{ background: #F00;}
.child {
  width:100px;
  height:100px;
}

.draggable.is-dragging { opacity: 0.7; }
.ui-resizable-helper{ border: 1px dotted #20a0ff; }
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<link href="https://jqueryui.com/resources/demos/style.css" rel="stylesheet"/>

<div class="draggable ui-widget-content father ">
  <p class ="p1">handle</p>
  <div id="resizable" class="draggable ui-widget-content child">
    <p class ="p2">handle</p>
    1234345 6
  </div>
  
</div>

EN

回答 1

Stack Overflow用户

发布于 2019-06-10 23:57:16

我会远离使用帮助器,我发现使用它们有很多问题。

在使用jquery-ui交互时,我在容器中使用了一个内部元素,这样小部件就不会受到容器中任何其他元素的影响。例如,由于"p1“元素,调整大小容器不能正常工作,为了避免这种情况,您可以像我一样添加一个内部元素,或者将任何其他内部元素设为position: absolute;,这样它们就不会影响ui-element。

下面是我的例子:

代码语言:javascript
复制
$('.father').draggable({
  handle: '.p1'
}).resizable({});

var containTo = $('.father-inner');
$('.child').draggable({
  handle: '.p2',
  containment: containTo
}).resizable({
  containment: containTo
});
代码语言:javascript
复制
body {
  font-family: sans-serif;
}

.father-inner {
  position: absolute;
  top: 40px;
  left: 5px;
  right: 5px;
  bottom: 5px;
}

.draggable {
  width: 300px;
  height: 300px;
  background: #eee;
  border: 1px solid #ccc;
  border-radius: 10px;
}

.draggable.is-pointer-down {
  background: #09F;
}

p {
  background: #F00;
}

.child {
  min-width: 100px;
  min-height: 100px;
  height: 100px;
  width: 100px;
}

.draggable.is-dragging {
  opacity: 0.7;
}

.ui-resizable-helper {
  border: 1px dotted #20a0ff;
}

.ui-resizable-se {
  width: 20px;
  height: 20px;
  position: absolute;
  bottom: 0;
  right: 0;
  cursor: se-resize;
  background: #aaa;
}
代码语言:javascript
复制
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="draggable ui-widget-content father ">
  <p class="p1">handle</p>
  <div class="father-inner">
    <div id="resizable" class="draggable ui-widget-content child">
      <p class="p2">handle</p>
      1234345 6
    </div>
  </div>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47628931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档