gpt4 book ai didi

javascript - 可调整大小的 html 元素

转载 作者:行者123 更新时间:2023-11-29 23:13:49 25 4
gpt4 key购买 nike

我想使用 jquery 库中的以下方法创建一个可调整大小的 div 容器 https://jqueryui.com/resizable/

我的代码是:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Resizable - Default functionality</title>
<style>
#resizable { width: 150px; height: 150px; padding: 0.5em; }
#resizable h3 { text-align: center; margin: 0; }
.ui-widget-content {
border: 1px solid #dddddd;
background: #ffffff;
color: #333333;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#resizable" ).resizable();
} );
</script>
</head>
<body>
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">Resizable</h3>
</div>
</body>
</html>

它不起作用。

控制台日志中没有任何错误,但我无法拖动边框并更改边框的大小。

我不明白为什么会有问题。

最佳答案

为了让 jquery-ui 按预期工作,您需要包含 css 文件:

https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css

这是您的代码,其中包含 css 文件:

$( function() {
$( "#resizable" ).resizable();
} );
#resizable { width: 150px; height: 150px; padding: 0.5em; }
#resizable h3 { text-align: center; margin: 0; }
.ui-widget-content {
border: 1px solid #dddddd;
background: #ffffff;
color: #333333;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">Resizable</h3>
</div>

关于javascript - 可调整大小的 html 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53355632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com