< div id ="Overlay" ></ div >
< div id =« Popup » > . </ div >
body
{
font-family: Arial, Tahoma, Sans-Serif;
font-size: 1em;
}
#Popup
{
visibility: hidden;
position: absolute;
left: 50%;
top: 50%;
background-color: #FFF;
padding: 10px;
}
#Overlay
{
visibility: hidden;
position: absolute;
left: 0;
top: 0;
width: 100%;
background-color: #000;
}
var MoodalBox = new Class({
// , .
// setOptions() Options.
Implements: [Options],
// , .
options: {
optionName1: defaultValue1,
optionName2: defaultValue2
},
// — .
initialize: function (options)
{
// ,
// ( , ).
this .setOptions(options);
// .
}
});
var MoodalBox = new Class({
Implements: [Options],
// .
options: {
// .
destinationOverlayOpacity: 0.7,
// .
allowManualClose: true
},
// .
// element — .
// overlay — .
initialize: function (element, overlay, options)
{
this .setOptions(options);
// .
this .element = $(element);
this .overlay = $(overlay);
// .
if ( this .options.allowManualClose)
// .
// : bind(param) this.hide, this
// param. bind, this this.hide ,
// , .. this.overlay.
this .overlay.addEvent( "click" , this .hide.bind( this ));
// .
this .targetCoords = this .element.getCoordinates();
// / .
// , CSS- , — .
this .fx = {
overlayAnimation: new Fx.Tween( this .overlay, { property: "opacity" }),
elementAnimation: new Fx.Tween( this .element, { property: "opacity" })
}
},
// .
show: function ()
{
// .
this .setPosition();
// ( ).
this .fx.overlayAnimation.start(0, this .options.destinationOverlayOpacity);
this .fx.elementAnimation.start(0, 1);
},
// .
hide: function ()
{
// ( ).
this .fx.overlayAnimation.start( this .options.destinationOverlayOpacity, 0);
this .fx.elementAnimation.start(1, 0);
},
//
// .
setPosition: function ()
{
this .element.setStyles({
"marginLeft" : -( this .targetCoords.width / 2),
"marginTop" : -( this .targetCoords.height / 2)
});
this .overlay.setStyles({
"top" : window.getScrollTop(),
"height" : window.getHeight()
});
}
});
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< title > Mootools plugin </ title >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< link href ="./Style.css" rel ="Stylesheet" type ="text/css" />
<!-- Mootools. -->
< script src ="../../MooToolsCore.js" type ="text/javascript" language ="javascript" ></ script >
<!-- . -->
<script src= "./MoodalBox.js" type= "text/javascript" language= "javascript" ></script>
<script type= "text/javascript" language= "javascript" >
//<![CDATA[
var popupFx = null ;
// DOM-.
// .
window.addEvent( "domready" , function () { popupFx = new MoodalBox( "Popup" , "Overlay" ); });
//]]>
</ script >
</ head >
< body >
< input type ="button" value ="Show popup" onclick ="popupFx.show();" />
< div id ="Overlay" ></ div >
< div id ="Popup" > . </ div >
</ body >
</ html >
popupFx = new MoodalBox( "Popup" , "Overlay" , { destinationOverlayOpacity: 0.3 });
Source: https://habr.com/ru/post/38187/
All Articles