jquery - Jquery 可拖动包含 - 选择器不起作用
问题描述
我的 JQuery 可拖动容器不起作用。它不断超出为它设置的界限。任何帮助表示赞赏。
$(function() {
$( "#crop_square" ).draggable();
containment: "#area_c"
});
<div id ="area_c" style="width:300px;height:300px;background:blue" >
<div id="crop_square" style="width:100px;height:100px;border:2px solid black;background:none"></div>
</div>
解决方案
您没有正确附加包含选项,请这样做(将选项作为参数传递给插件调用):
$( "#crop_square" ).draggable({
containment: "#area_c"
});
下面的工作片段:
$(function() {
$( "#crop_square" ).draggable({ containment: "#area_c" });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id ="area_c" style="width:300px;height:300px;background:blue" >
<div id="crop_square" style="width:100px;height:100px;border:2px solid black;background:none">drag</div>
</div>
有关可拖动小部件选项的更多信息,请点击此处。
推荐阅读
- mongodb - VPC peering下如何从外部连接到MongoDB Atlas?
- telegram-bot - 后台连续访问用户的实时位置
- docker - 如何检查两个容器是否正确链接?
- java - 无法在项目 spring-boot-keycloak 上执行目标 org.apache.maven.plugins:maven-clean-plugin:3.1.0:clean (default-clean)
- playframework - 如何配置 Ebean 集群?
- linux - 在 Linux 中使用 little endian 编译 PowerPC(e5500 系列)
- google-maps - 如何在 Google 地图上显示自定义矢量图块
- php - 从 API 获取多个请求时流明 + Angular 错误 500
- spring-security - Spring Boot 安全配置 OAuthSSO 和 ResourceServer
- ms-access - 将 MS Access 2003 Unicode 字符串读入 VB6