jquery Pop-up plug-in simplified version code 1th/2 page _jquery

Source: Internet
Author: User
Tags extend
Copy Code code as follows:

String.prototype.replaceAll = function (S1,S2) {
Return This.replace (New RegExp (S1, "GM"), S2);
};
(function ($) {
/*
* $-layer 0.1-new Wave Javascript
*
* Copyright (c) 2008 King Wong

* $Date: 2008-10-09 $
*/
var ___id___ = "";
var ___settings___ = {};
var ismousedown = false;

var currentelement = null;

var dropcallbacks = {};
var dragcallbacks = {};

var bubblings = {};

var lastmousex;
var Lastmousey;
var lastelemtop;
var lastelemleft;

var dragstatus = {};

var holdinghandler = false;

$.getmouseposition = function (e) {
var posx = 0;
var posy = 0;

if (!e) var e = window.event;

if (E.pagex | | e.pagey) {
Posx = E.pagex;
Posy = E.pagey;
}
else if (E.clientx | | e.clienty) {
POSX = e.clientx + Document.body.scrollLeft + document.documentElement.scrollLeft;
Posy = e.clienty + Document.body.scrollTop + document.documentElement.scrollTop;
}
return {' x ': posx, ' y ': posy};
};
$.updateposition = function (e) {
var pos = $.getmouseposition (e);

var SpanX = (pos.x-lastmousex);
var spany = (Pos.y-lastmousey);
var _top = (lastelemtop + spany) > 0? (Lastelemtop + Spany): 0;
var _left = (lastelemleft + SpanX) > 0? (Lastelemleft + SpanX): 0;
$ ("#" +___id___). CSS ("top", _top);
$ ("#" +___id___). CSS ("left", _left);
};

$.fn.ondrag = function (callback) {
Return This.each (function () {
Dragcallbacks[this.id] = callback;
});
};
$.fn.ondrop = function (callback) {
Return This.each (function () {
Dropcallbacks[this.id] = callback;
});
};

$.fn.dragoff = function () {
Return This.each (function () {
Dragstatus[this.id] = ' off ';
});
};

$.fn.dragon = function () {
Return This.each (function () {
Dragstatus[this.id] = ' on ';
});
};
$.extend ({
layersettings:{
ID: "Layerdiv",
width:220,
height:220,
Templete: ' <div style= ' height:20px; Width: @width @px; Background-color: #777777; " ><span id= "@moveid @" style= "position:relative; left:0px; top:0px; height:20px; width:100px; " ><span id= "@titleid @" > @title @</span></span><span class= "Layerclose style=" position: relative; top:0px; Float:right; right:20px; color:red; " >close</span></div><div style= "Border:solid #ff0000 1px; Width: @width @px; Height: @height @px; ><div style= "width:100%; height:100%; Background-color: #ffffff; "id=" @contentid @ "></div></div>",
Content: ',
Title: ',
Isbg:true,
opacity:0.3
},
Layersetup:function (Settings) {
$.extend ($.layersettings, settings);
___settings___[settings.id] = settings;
___id___ = settings.id;
},
Layershow:function () {
var __BW = $ ("Body"). width ();
var __bh = $ ("body"). Height () > $ (window). Height ()? $ ("body"). Height (): $ (window). Height ();
var _width = $.layersettings.width;
var _height = $.layersettings.height;

if (document.getElementById (___id___)) return;
var _moveid = ___id___ + "_move";
var _titleid = ___id___ + "_title";
var _contentid = ___id___ + "_content";
var _cssurl = $.layersettings.cssurl;
var opacity = $.layersettings.opacity;
__index = $.layermaxindex ();
var __left = (__BW-_width) > 0? (__BW-_width)/2:0;
var __top = 100;
var __bgdiv = ' <div id= ' +___id___+ ' _background ' style= ' background: #000000; Filter:alpha (opacity= ' + (opacity*100) + '); Opacity: ' +opacity+ '; Width: ' +__bw+ ' px; Height: ' +__bh+ ' px; Z-index: ' + (__index++) + '; Position:absolute; left:0px; top:0px; " ></div> ';
if ($.LAYERSETTINGS.ISBG)
{
$ ("Body"). Append (__bgdiv);
}
$ ("Body"). Append (' <div id= ' +___id___+ ' style= ' z-index: ' +__index+ ';p osition:absolute; Left: ' +__left+ ' px; Top: ' +__top+ ' px; ' ></div> ');
var _templete = $.layersettings.templete;
var __templete = _templete.replaceall ("@width @", _width). ReplaceAll ("@height @", _height). ReplaceAll ("@titleid @", _ TitleID). ReplaceAll ("@contentid @", _contentid). ReplaceAll ("@title @", jQuery.layerSettings.title). ReplaceAll ("@ moveid@ ", _moveid);
$ ("#" +___id___). Append (__templete);
$ ("#" +_contentid). Append ($.layersettings.content);
$ ("#" +_titleid). Append ($.layersettings.title);
var IDD = ___id___;
$ (". Layerclose"). Bind ("click", Function ()
{
$.layerclose (IDD);
});
$ ("#" +___id___). Bind ("click", Function ()
{
var id = this.id;
$.layersetup (___settings___[id]);
$ (this). CSS ("Z-index", $.layermaxindex ());
});
$ (document). Bind ("click", Function (e)
{
var pos = $.getmouseposition (e);

});
$ (document). MouseMove (function (e) {
if (Ismousedown && dragstatus[currentelement.id]!= ' false ') {
$.updateposition (e);
if (Dragcallbacks[currentelement.id]!= undefined) {
Dragcallbacks[currentelement.id] (E, currentelement);
}
return false;
}
});
$ (document). MouseUp (function (e) {
if (Ismousedown && dragstatus[currentelement.id]!= ' false ') {
Ismousedown = false;
if (Dropcallbacks[currentelement.id]!= undefined) {
Dropcallbacks[currentelement.id] (E, currentelement);
}
return false;
}
});
(function () {
BUBBLINGS[___ID___] = true;

DRAGSTATUS[___ID___] = "on";

SetHandler
Bubblings[this.id] = true;

Dragstatus[_moveid] = "handler";

$ ("#" +_moveid). CSS ("cursor", "move");

$ ("#" +_moveid). MouseDown (function (e) {
var id = this.id.replace ("_move", "");
___id___ = ID;
$ ("#" +id). CSS ("Z-index", $.layermaxindex ());
$.layersetup (___settings___[id]);
if ((dragstatus[___id___] = "Off") | | (dragstatus[___id___] = = "Handler" &&!holdinghandler))
return bubblings["#" +___id___];

Ismousedown = true;
Currentelement = $ ("#" +___id___);

var pos = $.getmouseposition (e);
Lastmousex = pos.x;
Lastmousey = Pos.y;

Lastelemtop = document.getElementById (___id___). offsettop;
Lastelemleft = document.getElementById (___id___). offsetleft;

$.updateposition (e);
Holdinghandler = true;
});

$ ("#" +_moveid). MouseUp (function (e) {
Holdinghandler = false;
});
End SetHandler
})();
},
Layerclose:function (__id)
{
$ ("#" +__id+ "_background"). Remove ();
$ ("#" +__id). Remove ();
},
Layermaxindex:function ()
{
var ___index = 0;
$.each ($ ("*"), function (i,n) {
var __tem = $ (n). CSS ("Z-index");
if (__tem>0)
{
if (__tem > ___index)
{
___index = __tem + 1;
}
}
});
return ___index;
}
});
}) (JQuery);


Current 1/2 page 12 Next read the full text

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.