Erstellen Sie eine Maskenebene
Die Codekopie lautet wie folgt:
_CreateCover: function () {
var newmask = document.createelement ("div");
newmask.id = this._mark;
Newmask.Style.position = "Absolute";
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 (opacity = 50)";
newmask.style.opacity = "0,50";
newmask.style.display = 'none';
document.body.appendchild (Newmask);
this._cover = newmask;
}
Erstellen Sie eine neue Popup-Ebene
Die Codekopie lautet wie folgt:
_createfloater: function (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 = 'none';
newdiv.innerhtml = html;
document.body.appendchild (newdiv);
this._floater = newdiv;
}
Passen Sie die Position der elastischen Schicht an
Die Codekopie lautet wie folgt:
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";
}
Passen Sie die Position an, wenn Bildschirm -Scrolling -Ereignisse
Die Codekopie lautet wie folgt:
this._fs = bindaseventListener (this, this.addjustPosition);
AddEventHandler (Fenster, "Scroll", this._fs);
// Nachdem du es versteckt hast, musst du
removentHandler (Fenster, "Scrollen", this._fs);
Vollständiger Code
Die Codekopie lautet wie folgt:
var floater = (function () {
var me = class.create ();
me.prototype = {
initialisieren: Funktion (Optionen) {
this._fs = bindaseventListener (this, this.addjustPosition);
this.SetOptions (Optionen);
},
SetOptionen: Funktion (Optionen) {
this.options = Optionen || {};
this._id = options.id;
this._mark = 'mark';
},
anzeigen: function (html, option) {
Optionen = Optionen || {};
if (! this._cover) {
this._CreateCover ();
}
if (! this._floater) {
this._createfloater (html);
}
if (options.saveopt) {
this._saveoption = options.saveopt;
this.bindsavevent ();
}
this._bindscRollevent ();
this.addjustPosition ();
this._floater.style.display = '';
this._cover.style.display = '';
this.isshow = true;
},
Einfügen: Funktion (html, opts, att) {
var _e = document.createelement ("div"), _t;
_e.innerhtml = html;
für (var k in opts) {
_e [k] = opts [k];
}
_t = this._floater.querySelector ('['+att+']');
if (_t) {
_t.AppendChild (_e);
}
},
getFloater: function () {
if (this._floater) {
Gibt dies zurück._Floater;
}
},
// Schicht maskieren
_CreateCover: function () {
var newmask = document.createelement ("div");
newmask.id = this._mark;
Newmask.Style.position = "Absolute";
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 (opacity = 50)";
newmask.style.opacity = "0,50";
newmask.style.display = 'none';
document.body.appendchild (Newmask);
this._cover = newmask;
},
// neue Popup-Schicht
_createfloater: function (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 = 'none';
newdiv.innerhtml = html;
document.body.appendchild (newdiv);
this._floater = newdiv;
},
// Die Popup-Ebene wird in die Mitte gescrollt
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";
},
bindsavevent: function () {
this._saveelem = this._floater.querySelector ('['+this._saveoption.elem+']');
if (this._saveelem) {
AddEventHandler (this._saveelem, "click", this._saveoption.handler);
}
},
_bindscollevent: function () {
AddEventHandler (Fenster, "Scroll", this._fs);
},
ausblenden: function () {
this.isshow = false;
this.destory ();
},
Destory: function () {
removentHandler (Fenster, "Scrollen", this._fs);
if (this._saveelem) {
removentHandler (this._saveelem, "click", 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;
}
};
bring mich zurück;
}) ();