jQuery对话框打开时窗口向上滚动 [英] Window scrolling up when jquery dialog opens up

查看:193
本文介绍了jQuery对话框打开时窗口向上滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jquery 1.4和jquery-ui-1.8rc3.custom.js打开模式jquery对话框

I am trying to open a modal jquery dialog using jquery 1.4 and jquery-ui-1.8rc3.custom.js

在所有浏览器中,对话框均无问题地打开,但是在IE 7和6中,对话框打开后,窗口将自身滚动到按钮...我试图将窗口向上滚动回到模态位置,但是是非常不一致的. 在打开模态后使用了以下代码

The dialog opens up with no issues, in all browsers, but in IE 7 and 6, after the dialog opens up, the window scrolls itself to the buttom... I tried scrolling the window up back to the modal position but is very inconsistent. was using the following line of code after opening up the modal

window.scrollTo($('#selector').dialog('option', 'position')[0],$('#selector').dialog('option', 'position')[1]);

我注意到的一件奇怪的事情是,当我打开模态后,页面变得巨大了……好像在底部增加了一些额外的东西……并最终滚动到了底部. 知道为什么这会使人震惊

One weird thing I am noticing is that after I open the modal, the page becomes huge... as if some extra things adds up on the bottom .... and it eventually scrolls to the bottom. Any idea why this could be hapenning

以html

<div id="selector">
</div>

在document.ready

in document.ready

$('#selector').dialog({
  bgiframe: true,
  autoOpen: false,
  width: 100,
  height: 100,
  modal: true,
  position: 'top'
});

在js

$('#selector').dialog('open');

推荐答案

好像您在选择器中缺少#:

Looks like you are missing the # in your selector:

window.scrollTo($('#selector').dialog('option', 'position')[0], $('#selector').dialog('option', 'position')[1]);

这可能就是窗口滚动到左上角的原因.

that might be why the window is scrolling to the left top corner.

我只是看文档,而.dialog('option','position')的默认值为center.

I was just looking at the documentation and .dialog('option','position') default value is center.

位置类型:字符串,数组默认值:"center"

position Type: String, Array Default: 'center'

指定对话框应在的位置 显示.可能的值:1)a 代表位置的单个字符串 在视口内:中心",左", 正确",顶部",底部". 2)一个数组 在其中包含x,y坐标对 距左上角的像素偏移 视口(例如[350,100])3)数组 包含x,y位置字符串值 (例如['right','top']代表右上角 角落).

Specifies where the dialog should be displayed. Possible values: 1) a single string representing position within viewport: 'center', 'left', 'right', 'top', 'bottom'. 2) an array containing an x,y coordinate pair in pixel offset from left, top corner of viewport (e.g. [350,100]) 3) an array containing x,y position string values (e.g. ['right','top'] for top right corner).

因此,您可以使用position选项获得文本或数字,而window.scrollTo()则需要数字.因此,请尝试以下方法:

So you could get text or numbers returned using the position option and window.scrollTo() requires numbers. So try this instead:

var d = $(".ui-dialog").position();
window.scrollTo( d.left , d.top);

这篇关于jQuery对话框打开时窗口向上滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆