JS实现可缩放、拖动、关闭和最小化的浮动窗口完(2)

var Window=document.createElement("div");
 Window.id="divWindow"+ name;
 Window.className="divWindow";
 Window.style.left=left+'px';
 Window.style.top=top+'px';
 Window.style.width=width+'px';
 Window.style.height=height+'px';
 Window.onclick=function(){
  if(parseInt(Window.style.zIndex)<=zindex){
   zindex++;
   Window.style.zIndex=zindex;
  }
 }
this.Window=Window;
//公有属性,类外可操作;若要在类外操作,可将元素改为公有属性
 
var Bar=document.createElement("div");
 Bar.id="divBar"+name;
 Bar.onselectstart="return false";
 Bar.className="divBar";
 Bar.onmousedown=this.mousedown;
 Bar.ondblclick=this.dblclick;
 Bar.onmousemove=this.mousemove;
 Bar.onmouseup=this.mouseup;
 Window.appendChild(Bar);
var Title=document.createElement("span");
 Title.id="divTitle"+ name;
 Title.className="divTitle";
 Title.style.width=(width-40)+'px';    //自适应标题长度
 Title.innerText=title;
 Bar.appendChild(Title);
var Change=document.createElement("span");
 Change.id="divChange"+ name;
 Change.className="divChange";
 Change.innerText="-";
 Change.ondblclick=this.changeWindow;
 Change.onclick=this.changeWindow;
 Bar.appendChild(Change);
var Close=document.createElement("span");
 Close.id="divClose"+ name;
 Close.onclick=function(){
  Window.style.display='none';
 }
 Close.className="divClose";
 Close.innerText="×";
 Bar.appendChild(Close);
var Content=document.createElement("div");
 Content.id="divContent"+ name;
 Content.className="divContent"
 Content.innerHTML=content;
 Content.style.height=parseInt(height-20)+'px';
 Window.appendChild(Content);
 
var ReSize=document.createElement("div");
 ReSize.className="divReSize";
 ReSize.onmousedown=function(){
  if(Window.style.zIndex<=zindex){
   zindex++;
   Window.style.zIndex=zindex;
  }
  ReSize.setCapture();
  isMouseDown=true;
 }
 ReSize.onmousemove=function(){
   if (isMouseDown && !maximum)
   {
   width=parseInt(event.clientX)-parseInt(Window.style.left)+5;
   height=parseInt(event.clientY)-parseInt(Window.style.top)+5;
   if(width>100){       //设置最小宽度
    Window.style.width=width+'px';
    Title.style.width=(width-40)+'px';
   }
   if(height>100){       //设置最小高度
    Window.style.height=height+'px';
    Content.style.height=parseInt(height-20)+'px';
   }
   }
 }
 ReSize.onmouseup=function(){
  ReSize.releaseCapture();
  isMouseDown=false;
 }
 Window.appendChild(ReSize);
var Iframe=document.createElement("iframe"); //添加iframe,IE6.0下遮挡<select>控件
 Iframe.className="divIframe";
 Window.appendChild(Iframe);
 
 document.body.appendChild(Window);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgfgdy.html