Home  >  Article  >  Web Front-end  >  为jquery.ui.dialog 增加“自动记住关闭时的位置”的功能_jquery

为jquery.ui.dialog 增加“自动记住关闭时的位置”的功能_jquery

WBOY
WBOYOriginal
2016-05-16 18:41:101006browse

经过摸索进行了扩展,增加“自动记住关闭时的位置”的功能,源码如下:

复制代码 代码如下:

//myJquery.ui.dialog.ex.js

////////////////////////////////////
//自动记住 jquery.ui.dialog关闭时的位置
///////////////////////////////////
(function($){
var originClose = $.ui.dialog.prototype.close;
$.ui.dialog.prototype.close = function()
{
//判断option中是否指定不使用此功能,如 $("#d").dialog({rememberPosition:false});
if(this.options.rememberPosition != false)
{
this.position = this.uiDialog.offset() ;
var top = $('body').scrollTop();
if(top == 0) top = $(document).scrollTop(); //修正!DOCTYPE BUG
var left = $('body').scrollLeft();
if(left == 0) left = $(document).scrollLeft(); //修正!DOCTYPE BUG
this.options.position = [this.position.left-left,this.position.top-top];
}
originClose.apply(this,arguments);
};
})(jQuery);

原理很简单,不再做特殊说明,有此需求的朋友可参考一下。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn