jQuery 动画弹出窗体支持多种展现方式

(编辑:jimmy 日期: 2024/10/11 浏览:2)

jQuery 动画弹出窗体支持多种展现方式"<img src=\"images/window_max.jpg\" id=\"windowMax\" />"+
"<img src=\"images/window_close.jpg\" id=\"windowClose\" />"+
"</div>"+
"<div id=\"windowBottom\"><div id=\"windowBottomContent\">&nbsp;</div></div>"+
"<div id=\"windowContent\"></div>"+
"<img src=\"images/window_resize.gif\" id=\"windowResize\" />"+
"</div>").appendTo("body");
},
_getWindowPosition : function(options){
var wPosition = $.alerts._getPosition("#window");
var windowPosition = {};
windowPosition.t = parseInt($(window).height()/6)+parseInt($(window).scrollTop());
windowPosition.l = ($(window).width()+$(window).scrollLeft())/2 - options.width/2;
windowPosition.w = options.width;
windowPosition.h = options.height;
return windowPosition;
},
_getPosition : function(o){
var top = $(o).offset().top;
var left = $(o).offset().left;
var height = $(o).height();
var width = $(o).width();
return {t:top,l:left,h:height,w:width};
},
Drag : function(obj,options){
var e = options.e || window.event;
var Drag = options.Drag;
if(Drag == false)return;
var x=parseInt(obj.style.left);
var y=parseInt(obj.style.top);
var x_=e.clientX-x;
var y_=e.clientY-y;
if(document.addEventListener){
document.addEventListener('mousemove', inFmove, true);
document.addEventListener('mouseup', inFup, true);
} else if(document.attachEvent){
document.attachEvent('onmousemove', inFmove);
document.attachEvent('onmouseup', inFup);
}
inFstop(e);
inFabort(e);
function inFmove(e){
var evt;
if(!e)e=window.event;
obj.style.left=e.clientX-x_+'px';
obj.style.top=e.clientY-y_+'px';
inFstop(e);
}
function inFup(e){
var evt;
if(!e)e=window.event;
if(document.removeEventListener){
document.removeEventListener('mousemove', inFmove, true);
document.removeEventListener('mouseup', inFup, true);
} else if(document.detachEvent){
document.detachEvent('onmousemove', inFmove);
document.detachEvent('onmouseup', inFup);
}
inFstop(e);
}
function inFstop(e){
if(e.stopPropagation) return e.stopPropagation();
else return e.cancelBubble=true;
}
function inFabort(e){
if(e.preventDefault) return e.preventDefault();
else return e.returnValue=false;
}
}
}
JAlert = function(o,json){
$.alerts.alert(o,json);
};
})(jQuery);

调用代码
复制代码 代码如下:
$(function(){
$("a").each(function(){
$(this).bind("click",function(){
JAlert(this,{
title : '提示窗体',
content : $("#msg")[0].outerHTML,
GetType : 'string', //controls,ajax,string,iframe
IsDrag : true,
Url : "windows.html",
Data : null,
width:300,
height:200
});
});
});
});

使用说明:
    title: 窗体标题
    content:取决于GetType属性,如果GetType='string',那么content就是要显示的内容,如果GetType='controls',那么content则为要显示的DOM对象。其它两个类型可不用填写。
    GetType:展现的四种类型:string,iframe,ajax,controls
    IsDrag:是否支持拖拽
    Url: 同样取决于GetType属性,如果GetType='ajax',那么Url就是请求的URL地址,如果GetType='iframe',那么URL就是iframe的链接地址。其它两个类型不用填写
    Data:当GetType='ajax'时,Data属性为请求的数据。
    width:显示层的宽度
    height:显示层的高度
  HTML代码
复制代码 代码如下:
<body>
<a href="javascript:void(0);" id="windowOpen1">Open window</a>
<a href="javascript:void(0);" id="windowOpen2">Open window</a> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<a href="javascript:void(0);" id="windowOpen3">Open window</a>
<div id="msg" style="font-size:16px;padding-top:16px;line-height:25px;">&nbsp;&nbsp;&nbsp;&nbsp;欢迎访问《<a href="http://jb51.net" target="_blank"></a>》的网站,希望与大家一起探讨技术问题,共同实现各自的梦想!<br/><br/>网址:http://jb51.net</div>
</body>

打包下载地址