我想创建一个简单的模态窗口,就像在这个示例http://jqueryui.com/dialog/中一样,当页面的主体在特定位置向下和向上滚动时浮动。它可以是右上角,右下角或右中角。
我使用过他的代码:
$(function () { $("#dialog").dialog({ maxHeight: 200, width: 400, autoOpen: true, show: { effect: "blind", duration: 1000 }, hide: { effect: "explode", duration: 1000 } }); $("#opener").click(function () { $("#dialog").dialog("open"); }); $(window).scroll(function () { //after window scroll fire it will add define pixel added to that element. set = $(document).scrollTop() + "px"; //this is the jQuery animate function to fixed the div position after scrolling. $('#dialog').animate({ top: set }, { duration: 1000, queue: false }); }); });
这怎么会只将文本浮动到对话框内而不是整个窗口。
非常感谢任何帮助:)
答案 0 :(得分:1)
尝试将“#dialog”选择器更改为“。ui-dialog”,
$(window).scroll(function () {
//after window scroll fire it will add define pixel added to that element.
set = $(document).scrollTop() + "px";
//this is the jQuery animate function to fixed the div position after scrolling.
$('.ui-dialog').animate({ top: set }, { duration: 1000, queue: false });
});
因为 $('#dialog')会在jQuery UI创建对话框后转换为新的DOM元素,并且可以通过 $('。 UI-对话框')强>