標籤:cursor 事件 htm hover box title sem 選中 接收
tanchuang.js
// 每個彈窗的標識var x =0;var idzt = new Array();var Window = function(config){ //ID不重複 idzt[x] = "zhuti"+x; //彈窗ID //初始化,接收參數 this.config = { width : config.width || 300, //寬度 height : config.height || 200, //高度 buttons : config.buttons || ‘‘, //預設無按鈕 title : config.title || ‘標題‘, //標題 content : config.content || ‘內容‘, //內容 isMask : config.isMask == false?false:config.isMask || true, //是否遮罩 isDrag : config.isDrag == false?false:config.isDrag || true, //是否移動 }; //載入快顯視窗 var w = ($(window).width()-this.config.width)/2; var h = ($(window).height()-this.config.height)/2; var nr = "<div class=‘zhuti‘ id=‘"+idzt[x]+"‘ bs=‘"+x+"‘ style=‘width:"+this.config.width+"px; height:"+this.config.height+"px; background-color:white; left:"+w+"px; top:"+h+"px;‘></div>"; $("body").append(nr); //載入彈窗標題 var content ="<div id=‘title"+x+"‘ class=‘title‘ bs=‘"+x+"‘>"+this.config.title+"<div id=‘close"+x+"‘ class=‘close‘ bs=‘"+x+"‘>×</div></div>"; //載入彈窗內容 var nrh = this.config.height - 75; content = content+"<div id=‘content"+x+"‘ bs=‘"+x+"‘ class=‘content‘ style=‘width:100%; height:"+nrh+"px;‘>"+this.config.content+"</div>"; //載入按鈕 content = content+"<div id=‘btnx"+x+"‘ bs=‘"+x+"‘ class=‘btnx‘>"+this.config.buttons+"</div>"; //將標題、內容及按鈕添加進視窗 $(‘#‘+idzt[x]).html(content); //建立遮罩層 if(this.config.isMask) { var zz = "<div id=‘zz‘></div>"; $("body").append(zz); $("#zz").css(‘display‘,‘block‘); } //最大最小限制,以免移動到頁面外 var maxX = $(window).width()-this.config.width; var maxY = $(window).height()-this.config.height; var minX = 0, minY = 0; //視窗移動 if(this.config.isDrag) { //滑鼠移動彈出窗 $(".title").bind("mousedown",function(e){ var n = this.getAttribute("bs"); //取標識 //使選中的到最上層 $(".zhuti").css("z-index",3); $(‘#‘+idzt[n]).css("z-index",4); //取初始座標 var endX = 0, //移動後X座標 endY = 0, //移動後Y座標 startX = parseInt($(‘#‘+idzt[n]).css("left")), //彈出層的初始X座標 startY = parseInt($(‘#‘+idzt[n]).css("top")), //彈出層的初始Y座標 downX = e.clientX, //滑鼠按下時,滑鼠的X座標 downY = e.clientY; //滑鼠按下時,滑鼠的Y座標 //綁定滑鼠移動事件 $("body").bind("mousemove",function(es){ endX = es.clientX - downX + startX; //X座標移動 endY = es.clientY - downY + startY; //Y座標移動 //最大最小限制 if(endX > maxX) { endX = maxX; } else if(endX < 0) { endX = 0; } if(endY > maxY) { endY = maxY; } else if(endY < 0) { endY = 0; } $(‘#‘+idzt[n]).css("top",endY+"px"); $(‘#‘+idzt[n]).css("left",endX+"px"); window.getSelection ? window.getSelection().removeAllRanges():document.selection.empty(); //取消選中文本 }); }); //滑鼠按鍵抬起,釋放移動事件 $("body").bind("mouseup",function(){ $("body").unbind("mousemove"); }); } //關閉視窗 $(".close").click(function(){ var m = this.getAttribute("bs"); //找標識 $(‘#‘+idzt[m]).remove(); //移除彈窗 $(‘#zz‘).remove(); //移除遮罩 }) x++; //標識增加 }
tanchuang.css
.zhuti{ position:absolute; z-index:3; font-size:14px; border-radius:5px; box-shadow:0 0 5px white; overflow:hidden; color:#333;}.title{ background-color:#3498db; vertical-align:middle; height:35px; width:100%; line-height:35px; text-indent:1em;}.close{ float:right; width:35px; height:35px; font-weight:bold; line-height:35px; vertical-align:middle; color:white; font-size:18px; }.close:hover{ cursor:pointer;}.content{ text-indent:1em; padding-top:10px;}.btnx{ height:30px; width:100%; text-indent:1em;}.btn{ height:28px; width:80px; float:left; margin-left:20px; color:#333;}#zz{ width:100%; height:100%; opacity:0.15; display:none; background-color:#ccc; z-index:2; position:absolute; top:0px; left:0px;}
AJAX裡使用的彈窗樣式 tanchuang.js tanchuang.css