简体   繁体   English

带有选项卡的jQuery UI对话框

[英]jQuery UI dialog with tabs

I am using a tabbed interface with jQuery UI. 我在jQuery UI中使用选项卡式界面。 That is working fine. 很好 Each tab is actually a form. 每个选项卡实际上都是一个表单。 So when that form is submitted the action brings the user back to the same page. 因此,在提交该表单时,操作会将用户带回到同一页面。 But at that point I want to open the appropriate tag. 但是到那时我想打开适当的标签。

So, I am using a URL which looks something like this. 因此,我使用的URL看起来像这样。

domain.com/page.php#tab1 domain.com/page.php#tab1

Which works fine and opens the correct tab. 可以正常工作并打开正确的选项卡。 There is a slight issue with the scroll position of the page. 页面的滚动位置略有问题。 Which is due to the anchor position on the page. 这是由于页面上的锚点位置。 I want the scroll to be at the top of the page so I am using something like this to get back to the top. 我希望滚动条位于页面顶部,所以我正在使用类似的方法回到顶部。

$('html, body').animate({ scrollTop: 0 });

So, all that is fine. 所以,一切都很好。 However, I then open a modal dialog and it is positioned incorrectly because of the scroll that has happened. 但是,然后打开一个模式对话框,由于发生了滚动,它的位置不正确。

I have done research and have found this suggestion for repositioning the modal : 我已经进行了研究,发现了重新定位模式的建议:

$('my-selector').dialog('option', 'position', 'center');

but that does not seem to work. 但这似乎不起作用。

So how do I get this to play nice ? 那么,如何使它发挥出色呢?

My simplified code is as follows: 我的简化代码如下:

html html

<div id="tester">
</div>

scripts - in document ready 脚本-已准备好文档

$('html, body').animate({ scrollTop: 0 });#

jQuery('#tester').dialog
({
title: "Attribute " ,
minWidth: 840,
height:500
});

Actually in the real version the dialog is opened with a click handler. 实际上,在实际版本中,对话框是通过单击处理程序打开的。 So, the animation is definitely complete by the time the dialog is opened. 因此,在打开对话框时,动画肯定已经完成。 So I am confused about why the modal is appearing at the bottom of the page. 因此,我很困惑为什么该模式出现在页面底部。

Thanks in advance 提前致谢

If you ensure that the dialog is opened on the complete callback of the .animate() method, you should not have any issues. 如果确保在.animate()方法的完整回调上打开对话框,则应该没有任何问题。

What is likely occurring is that the animation is still in transition while the dialog is being opened, so the internal calculations for its position are incorrect. 可能发生的情况是,在打开对话框时动画仍处于过渡状态,因此其位置的内部计算不正确。 Below is a basic example: 以下是一个基本示例:

$('#button').click(function () {
    $('html, body').animate({
        scrollTop: 0
    }, openDialog);
});

function openDialog() {
    jQuery('#tester').dialog({
        title: "Attribute ",
        minWidth: 840,
        height: 500
    });
}

jsfiddle jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM