Créer une couche de masque
La copie de code est la suivante:
_CreateCover: function () {
var newmask = document.CreateElement ("div");
newmask.id = this._mark;
newmask.style.position = "absolu";
newmask.style.zindex = "100";
_scrollWidth = math.max (document.body.scrollwidth, document.documentElement.scrollWidth);
_scrollHeight = math.max (document.body.scrollHeight, document.DocumentElement.ScrollHeight);
newmask.style.width = _scrollWidth + "px";
newmask.style.height = _scrollHeight + "px";
newmask.style.top = "0px";
newmask.style.left = "0px";
newmask.style.background = "# 000";
newmask.style.filter = "alpha (opacité = 50)";
newmask.style.opacity = "0,50";
newmask.style.display = 'Aucun';
Document.Body.ApendChild (Newmask);
this._cover = newmask;
}
Créer une nouvelle couche pop-up
La copie de code est la suivante:
_CreateFloater: fonction (html) {
var newDiv = document.CreateElement ("div");
newDiv.id = this._id;
newDiv.style.position = "Absolute";
newDiv.style.zindex = "9999";
newDivWidth = 400;
newDivheight = 200;
newDiv.style.width = newDivWidth + "px";
newDiv.style.height = newDivheight + "px";
newDiv.style.top = (document.body.scrolltop + document.body.clientHeight / 2 - newDivheight / 2) + "px";
newDiv.style.left = (document.body.scrollleft + document.body.clientwidth / 2 - newDivWidth / 2) + "px";
newDiv.style.padding = "5px";
newDiv.style.display = 'Aucun';
newDiv.InnerHtml = html;
document.body.ApendChild (newDiv);
this._floater = newDiv;
}
Ajuster la position de la couche élastique
La copie de code est la suivante:
AddJustPosition: function () {
this._floater.style.top = (document.body.scrolltop + document.body.clientHeight / 2 - newDivheight / 2) + "px";
this._floater.style.left = (document.body.scrollleft + document.body.clientwidth / 2 - newDivWidth / 2) + "px";
}
Ajustez la position lorsque les événements de défilement de l'écran
La copie de code est la suivante:
this._fs = bindaseventListener (this, this.addjustPosition);
addEventHandler (fenêtre, "scroll", this._fs);
// Après l'avoir caché, vous devez
retireEventHandler (fenêtre, "Scroll", this._fs);
Code complet
La copie de code est la suivante:
var Floater = (function () {
var me = class.create ();
me.prototype = {
initialiser: fonction (options) {
this._fs = bindaseventListener (this, this.addjustPosition);
this.setOptions (options);
},
setOptions: fonction (options) {
this.options = options || {};
this._id = options.id;
this._mark = 'mark';
},
show: function (html, options) {
Options = Options || {};
if (! this._cover) {
this._createCover ();
}
if (! this._floater) {
this._createfloater (html);
}
if (options.saveopt) {
this._saveOption = options.saveopt;
this.bindsaveevent ();
}
this._bindscrollevent ();
this.AddjustePosition ();
this._floater.style.display = '';
this._cover.style.display = '';
this.isshow = true;
},
insert: fonction (html, opts, att) {
var _e = document.createElement ("div"), _t;
_e.innerhtml = html;
pour (var k en opts) {
_e [k] = opts [k];
}
_t = this._floater.QuerySelector ('[' + att + ']');
if (_t) {
_t.ApendChild (_e);
}
},
getFloater: function () {
if (this._floater) {
Renvoie ce._floater;
}
},
// Masque Couche
_CreateCover: function () {
var newmask = document.CreateElement ("div");
newmask.id = this._mark;
newmask.style.position = "absolu";
newmask.style.zindex = "100";
_scrollWidth = math.max (document.body.scrollwidth, document.documentElement.scrollWidth);
_scrollHeight = math.max (document.body.scrollHeight, document.DocumentElement.ScrollHeight);
newmask.style.width = _scrollWidth + "px";
newmask.style.height = _scrollHeight + "px";
newmask.style.top = "0px";
newmask.style.left = "0px";
newmask.style.background = "# 000";
newmask.style.filter = "alpha (opacité = 50)";
newmask.style.opacity = "0,50";
newmask.style.display = 'Aucun';
Document.Body.ApendChild (Newmask);
this._cover = newmask;
},
// nouveau couche pop-up
_CreateFloater: fonction (html) {
var newDiv = document.CreateElement ("div");
newDiv.id = this._id;
newDiv.style.position = "Absolute";
newDiv.style.zindex = "9999";
newDivWidth = 400;
newDivheight = 200;
newDiv.style.width = newDivWidth + "px";
newDiv.style.height = newDivheight + "px";
newDiv.style.top = (document.body.scrolltop + document.body.clientHeight / 2 - newDivheight / 2) + "px";
newDiv.style.left = (document.body.scrollleft + document.body.clientwidth / 2 - newDivWidth / 2) + "px";
newDiv.style.padding = "5px";
newDiv.style.display = 'Aucun';
newDiv.InnerHtml = html;
document.body.ApendChild (newDiv);
this._floater = newDiv;
},
// La couche pop-up est défilée au centre
AddJustPosition: function () {
this._floater.style.top = (document.body.scrolltop + document.body.clientHeight / 2 - newDivheight / 2) + "px";
this._floater.style.left = (document.body.scrollleft + document.body.clientwidth / 2 - newDivWidth / 2) + "px";
},
bindsaveevent: function () {
this._saveelem = this._floater.queryselector ('[' + this._saveOption.elem + ']');
if (this._saveelem) {
addEventHandler (this._saveelem, "cliquez", this._saveOption.handler);
}
},
_bindscrolllevent: function () {
addEventHandler (fenêtre, "scroll", this._fs);
},
masquer: function () {
this.isshow = false;
this.destory ();
},
destory: function () {
retireEventHandler (fenêtre, "Scroll", this._fs);
if (this._saveelem) {
retireEventHandler (this._saveelem, "cliquez", this._saveOption.handler);
}
if (this._cover) {
document.body.removechild (this._cover);
}
if (this._floater) {
document.body.removechild (this._floater);
}
this._cover = null;
this._floater = null;
}
};
me rendre;
}) ();