javascript - 如何使用 css 属性 jquery 弹出窗口
问题描述
我希望每当我单击按钮(对话框)时,应该打开带有 html 的弹出窗口(在 somediv 标签内),弹出窗口正在打开,但我想增加弹出窗口的宽度并移动到屏幕的左侧而不是中间,我该怎么做? 这是我的代码
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script type="text/javascript">
function openDialog() {
$("#somediv").dialog({
modal: true
});
}
</script>
</head>
<style>
#somediv {
display: none;
}
</style>
<body>
<div id="somediv">
<div class="row clear">
<div class="col-md-4 ">
<div class="border text-center">
<p class="black-text">$50</p>
<h2 class="black-text light">1 Month</h2>
<p>5 Job Postings</p>
<p>Resume Search</p>
</div>
</div>
<div class="col-md-4">
<div class="border text-center">
<p class="black-text">$140</p>
<h2 class="black-text light">3 Month</h2>
<p>10 Job Postings</p>
<p>Resume Search</p>
</div>
</div>
<div class="col-md-4">
<div class="border text-center">
<p class="black-text">$400</p>
<h2 class="black-text light">Annual</h2>
<p>Unlimited Job Postings</p>
<p>Resume Search</p>
</div>
</div>
</div>
</div>
<a href="#" onclick="openDialog();">Dialog</a>
</body>
解决方案
指定对话框打开时应显示的位置。该对话框将处理冲突,以使尽可能多的对话框可见。
该of
属性默认为窗口,但您可以指定另一个要定位的元素。有关可用属性的更多详细信息,您可以参考jQuery UI Position实用程序。
代码示例:使用position
指定的选项初始化对话框:
function openDialog() {
$("#somediv").dialog({
modal: true,
width: 500, // or you can have it in %
height: 400, // or you can have it in %
position: { my: "left top", at: "left bottom", of: window }
});
}
注意:如果需要,您也可以使用 css 样式来调整宽度和高度
推荐阅读
- .net - TLS 1.3 问题,使用更高版本的 Docker 镜像 dotnet 或产生安全问题
- python-3.x - 如何使用正则表达式使用数组中的模式列表查找所有形式的日期
- javascript - 如何让我的 DIVS 像按钮一样更改内容,而不在 html 上添加 onclick 功能
- r - 从 R 版本 3.6.1 升级到 4.1.1 后 NextMethod 不起作用
- sql - 如果我必须选择几种类型的用户,如何避免“错误:不允许聚合聚合”?
- python - Python,使用 np.fromfile 从 n 个字节中读取一个字节
- python - 从 url 派生协议
- docker - 错误!docker container' 不是 Play 的有效属性
- java - 在 Twilio 中,如何在不使用消息模板的情况下在 24 小时会话中使用 Whatsapp 按钮或列表选项
- azure - 是否可以运行报告来查看谁有权访问 Azure 订阅上的 Application Insights 实例?