CopyCode The Code is 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.doc umentelement. scrollleft;
Posy = E. clienty + document. Body. scrolltop + document.doc umentelement. 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 );
$ ("#" +___Id1__).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 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> ',
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 = pai.layersettings.css URL;
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 + '; position: 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 );