gpt4 book ai didi

jquery-ui - 在 div 中保留一个 jQuery 对话框

转载 作者:行者123 更新时间:2023-12-03 08:13:22 25 4
gpt4 key购买 nike

我正在尝试创建许多 jQuery 对话框,但我想将它们的位置限制在父 div 内。我正在使用以下代码来创建它们(附带说明 oppacity 选项也不起作用......):

var d= $('<div title="Title goes here"></div>').dialog({
autoOpen: true,
closeOnEscape: false,
draggable: true,
resizable: false,
width: dx,
height: dy
});

d.draggable('option', 'containment', 'parent');
d.draggable('option', 'opacity', 0.45);

$('#controlContent').append(d.parent());

最佳答案

上述解决方案的一个更有帮助和完整的版本。

它甚至还限制了 div 之外的调整大小!

并且对 JavaScript 进行了完整的注释。

// Public Domain
// Feel free to use any of the JavaScript, HTML, and CSS for any commercial or private projects. No attribution required.
// I'm not responsible if you blow anything up with this code (or anything else you could possibly do with this code).

jQuery(function($)
{
// When the document is ready run the code inside the brackets.
$("button").button(); // Makes the button fancy (ie. jquery-ui styled)
$("#dialog").dialog(
{
// Set the settings for the jquery-ui dialog here.
autoOpen: false, // Don't open the dialog instantly. Let an event such as a button press open it. Optional.
position: { my: "center", at: "center", of: "#constrained_div" } // Set the position to center of the div.
}).parent().resizable(
{
// Settings that will execute when resized.
containment: "#constrained_div" // Constrains the resizing to the div.
}).draggable(
{
// Settings that execute when the dialog is dragged. If parent isn't used the text content will have dragging enabled.
containment: "#constrained_div", // The element the dialog is constrained to.
opacity: 0.70 // Fancy opacity. Optional.
});

$("#button").click(function()
{
// When our fancy button is pressed the stuff inside the brackets will be executed.
$("#dialog").dialog("open"); // Opens the dialog.
});
});

http://jsfiddle.net/emilhem/rymEh/33/

关于jquery-ui - 在 div 中保留一个 jQuery 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6315262/

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