ネイティブ JS を使用してポップアップ レイヤー効果を実装する_JavaScript スキル
创建遮罩层
_createCover: function() {
var newMask = document.createElement("div");
newMask.id = this._mark;
newMask.style.position = "絶対";
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;
}
新建弹出层
_createFloater: function(html) {
var newDiv = document.createElement("div");
newDiv.id = this._id;
newDiv.style.position = "絶対";
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;
}
调节弹层の位置
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";
}
画面滚動イベント時間调整位置
this._fS = BindAsEventListener(this, this.addjustPosition);
addEventHandler(window, "scroll", this._fS);
// 隐藏後必要
RemoveEventHandler(window, "scroll", this._fS);
完整代码
var Floater = (function(){
var me = Class.create();
me.prototype = {
初期化: function(options) {
this._fS = BindAsEventListener(this, this.addjustPosition);
this.setOptions(オプション);
}、
setOptions: function(options) {
this.options = オプション || {};
this._id = options.id;
this._mark = 'マーク';
}、
show: function(html,options) {
オプション = オプション || {};
if(!this._cover){
this._createCover();
}
if(!this._floater){
this._createFloater(html);
}
if(options.saveOpt){
this._saveOption = options.saveOpt;
this.bindSaveEvent();
}
this._bindScrollEvent();
this.addjustPosition();
this._floater.style.display = '';
this._cover.style.display = '';
this.isShow = true;
}、
挿入: function(html,opts,att){
var _e = document.createElement("div"), _t;
_e.innerHTML = html;
for(opts の var k){
_e[k] = opts[k];
}
_t = this._floater.querySelector('[' att ']');
if(_t){
_t.appendChild(_e);
}
}、
getFloater: function(){
if(this._floater){
これを返します。_floater;
}
}、
//遮罩层
_createCover: function() {
var newMask = document.createElement("div");
newMask.id = this._mark;
newMask.style.position = "絶対";
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;
}、
//新弹出层
_createFloater: function(html) {
var newDiv = document.createElement("div");
newDiv.id = this._id;
newDiv.style.position = "絶対";
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;
}、
//弹出层滚活動居中
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, "クリック", this._saveOption.handler);
}
}、
_bindScrollEvent: function() {
addEventHandler(window, "scroll", this._fS);
}、
非表示: function() {
this.isShow = false;
this.destory();
}、
デストリー: function() {
RemoveEventHandler(window, "scroll", this._fS);
if(this._saveElem){
RemoveEventHandler(this._saveElem, "クリック", 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;
}
};
返してください;
})();

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック











JavaScript文字列置換法とFAQの詳細な説明 この記事では、javaScriptの文字列文字を置き換える2つの方法について説明します:内部JavaScriptコードとWebページの内部HTML。 JavaScriptコード内の文字列を交換します 最も直接的な方法は、置換()メソッドを使用することです。 str = str.replace( "find"、 "置換"); この方法は、最初の一致のみを置き換えます。すべての一致を置き換えるには、正規表現を使用して、グローバルフラグGを追加します。 str = str.replace(/fi

単純なJavaScript関数は、日付が有効かどうかを確認するために使用されます。 関数isvaliddate(s){ var bits = s.split( '/'); var d = new Date(bits [2] '/' bits [1] '/'ビット[0]); return !!(d &&(d.getmonth()1)== bits [1] && d.getdate()== number(bits [0])); } //テスト var

この記事では、jQueryを使用して、DOM要素の内側のマージン値とマージン値、特に外側の縁と要素の内側の縁の特定の位置を取得して設定する方法について説明します。 CSSを使用して要素の内側と外側の縁を設定することは可能ですが、正確な値を取得するのは難しい場合があります。 // 設定 $( "div.header")。css( "margin"、 "10px"); $( "div.header")。css( "padding"、 "10px"); このコードはそうだと思うかもしれません

この記事では、10個の例外的なjQueryタブとアコーディオンについて説明します。 タブとアコーディオンの重要な違いは、コンテンツパネルの表示方法と非表示にあります。これらの10の例を掘り下げましょう。 関連記事:10 jQueryタブプラグイン

ウェブサイトのダイナミズムと視覚的な魅力を高めるために、10の例外的なjQueryプラグインを発見してください!このキュレーションされたコレクションは、画像アニメーションからインタラクティブなギャラリーまで、多様な機能を提供します。これらの強力なツールを探りましょう。 関連投稿: 1

HTTP-Consoleは、HTTPコマンドを実行するためのコマンドラインインターフェイスを提供するノードモジュールです。 Webサーバー、Web Servに対して作成されているかどうかに関係なく、HTTPリクエストで何が起こっているかをデバッグして正確に確認するのに最適です

このチュートリアルでは、カスタムGoogle検索APIをブログまたはWebサイトに統合する方法を示し、標準のWordPressテーマ検索関数よりも洗練された検索エクスペリエンスを提供します。 驚くほど簡単です!検索をyに制限することができます

次のjQueryコードスニペットを使用して、Divコンテンツがコンテナ要素領域を超えたときにスクロールバーを追加できます。 (デモンストレーションはありません、それを直接firebugにコピーしてください) // d =ドキュメント // w =ウィンドウ // $ = jQuery var contentarea = $(this)、 wintop = contentarea.scrolltop()、 docheight = $(d).height()、 winheight = $(w).height()、 divheight = $( '#c
