JQuery animation pop-up form supports multiple presentation modes _jquery

Source: Internet
Author: User


Animation effects
From which object is triggered from the beginning of the object gradually moving to the middle of the screen, and gradually expand, after the expansion of the display object from top to bottom slowly unfold. When you click Close, the expanded display object is slowly retracted and then slowly moved to the trigger object.
Said a bit around, I do not understand what it means, frankly, where to go back and forth.
Show Way
First Type: string
This is the simplest and most straightforward way, and needless to say, the direct assignment string is displayed.
The second type: Ajax
This is the presentation that supports Ajax, which is to get the data asynchronously and show it.
The third type: IFRAME
As the name implies, supports nested IFRAME display.
The fourth kind: controls
The name is a little bit too good to understand, is to show the page of an object. For example: document.getElementById ("ShowName");
Plug-in code implementation

Copy Code code as follows:

(function ($) {
$.alerts = {
Alert:function (o,options) {
var defaults = {
Title: ' Headline ',
Content: ' Contents ',
GetType: ' String ',//controls,ajax,string,iframe
Isdrag:true,
URL: ',
Data:null,
width:400,
HEIGHT:300,
Callback:function () {}
}
var options = $.extend (defaults,options);
if (!$ ("#window") [0])
{
$.alerts._createobject ();
}
var position = $.alerts._getposition (o);
var winposition = $.alerts._getwindowposition (options);
$ ("#windowContent"). Hide ();
$ ("#window"). CSS (
{
WIDTH:POSITION.W,
Height:position.h,
TOP:POSITION.T,
LEFT:POSITION.L,
zindex:1001
}
);
$ ("#windowBottom, #windowBottomContent"). CSS (
{
Height:options.height-30
}
);
$ ("#windowContent"). CSS (
{
Height:options.height-45,
width:options.width-25
}
);
$ ("#windowTopContent"). HTML (options.title);
Switch (options. GetType) {
Case "string":
$ ("#windowContent"). HTML (options.content);
Break
Case "Ajax":
if (options. URL = = "") {
Alert ("Ajaxurl cannot be empty");
Return
}else{
$.ajax (
{
Type: "POST",
Url:options. Url
Data:options. Data,
Success:function (msg) {
$ ("#windowContent"). HTML (msg);
}
}
);
}
Break
Case "Controls":
$ ("#windowContent"). HTML (Options.content.innerHTML);
Break
Case "iframe":
$ ("#windowContent"). empty ();
$ ("<iframe>"). attr (
{
Src:options. Url
Width:options.width,
Height:options.height
}
). Appendto ("#windowContent");
Break
}
$ ("#window"). Animate (
{
LEFT:WINPOSITION.L,
TOP:WINPOSITION.T,
Height:winposition.h,
Width:winposition.w
},500,function () {
$ ("#windowContent"). FadeIn (' slow ');
$ ("#windowContent"). Slidedown (600);
if ($ ("#middleElement_bgDiv"). Get (). length = = 0) {
$ ("<div>"). attr ("id", "middleelement_bgdiv"). CSS (
{
Position: "Absolute",
Left: "0px",
Top: "0px",
width:$ (window). Width () + "px",
Height:Math.max ($ ("body"). Height (), $ (window). Height ()) + "px",
Filter: "Alpha (opacity=40)",
Opacity: "0.4",
BackgroundColor: "#AAAAAA",
ZIndex: "1000",
margin: "0px",
padding: "0px"
}
). Appendto ("body");
}else{
$ ("#middleElement_bgDiv"). Show ();
}
}
);
$ ("#windowClose"). One ("click", Function () {
$ ("#windowContent"). Slideup (600,function () {
$ ("#window"). Animate (
{
LEFT:POSITION.L,
TOP:POSITION.T,
Height:position.h,
Width:position.w
},500,function () {
$ (this). Hide ();
if ($ ("#middleElement_bgDiv"). Get (). length > 0) {
$ ("#middleElement_bgDiv"). Hide ();
}
$ ("#window"). CSS (
{
LEFT:WINPOSITION.L,
TOP:WINPOSITION.T,
Height:winposition.h,
Width:winposition.w
}
);
}
);
})
});
$ ("#windowTop"). MouseDown (function () {
$.alerts. Drag (
document.getElementById ("Window"),
{
E:event,
Drag:options. Isdrag
}
);
});
},
_createobject:function () {
$ ("<div id=\" window\ ">" +
"<div id=\" windowtop\ ">" +
"<div id=\" windowtopcontent\ ">window example</div>" +
"<img src=\" images/window_min.jpg\ "id=\" windowmin\ "/>" +
"<img src=\" images/window_max.jpg\ "id=\" windowmax\ "/>" +
"<img src=\" images/window_close.jpg\ "id=\" windowclose\ "/>" +
"</div>" +
"<div id=\" windowbottom\ "><div id=\" windowbottomcontent\ "> </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);

Calling code
Copy Code code as follows:

$ (function () {
$ ("a"). each (function () {
$ (this). Bind ("click", Function () {
Jalert (this,{
Title: ' Prompt Form ',
Content: $ ("#msg") [0].outerhtml,
GetType: ' String ',//controls,ajax,string,iframe
Isdrag:true,
URL: "Windows.html",
Data:null,
WIDTH:300,
height:200
});
});
});
});

Instructions for use:
Title: Form Header
Content: Depending on the GetType attribute, if gettype= ' string ', then the content is what is to be displayed, if gettype= ' controls ', then the content is the DOM object to display. The other two types may not be filled in.
GetType: Four types of presentation: String,iframe,ajax,controls
Isdrag: Do you support dragging and dragging
URL: Also depends on the GetType attribute, if Gettype= ' ajax ', then URL is the URL of the request, if gettype= ' iframe ', then the URL is the link address of the IFRAME. Two other types are not required
Data: When Gettype= ' Ajax ', the date property is requested.
Width: Display the breadth of the layer
Height: Display Layer Heights
HTML code
Copy Code code as follows:

<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/>
<a href= "javascript:void (0);" id= "WindowOpen3" >open window</a>
<div id= "msg" style= "font-size:16px;padding-top:16px;line-height:25px;" > Welcome to visit the "<a href=" http://jb51.net "target=" _blank "> Cloud-Habitat </a>" site, I hope to discuss technical issues with you, and jointly realize their dreams! <br/><br/> website:http://jb51.net</div>
</body>

Package Download Address

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.