欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS實現(xiàn)可拖曳、可關(guān)閉的彈窗效果

 更新時間:2015年09月26日 10:45:58   作者:企鵝  
這篇文章主要介紹了JS實現(xiàn)可拖曳、可關(guān)閉的彈窗效果,可實現(xiàn)點擊文字彈出可拖動的窗口,同時背景出現(xiàn)變暗的遮罩效果,點擊遮罩層即可關(guān)閉彈出,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了JS實現(xiàn)可拖曳、可關(guān)閉的彈窗效果。分享給大家供大家參考。具體如下:

運行該實例,點擊文字,彈出一個窗口,其實是一個彈出層,這個彈出層可以隨鼠標(biāo)拖曳,另外,示例演示了用本方法彈出文字層和彈出圖片層的具體代碼,請根據(jù)選擇使用哦。

運行效果截圖如下:

在線演示地址如下:

http://demo.jb51.net/js/2015/js-draw-close-able-alert-dlg-demo/

具體代碼如下:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>彈出層、彈窗效果+拖曳功能 </title>
<style type="text/css">
 *{ margin:0px; padding:0px;}
 body{ font-size:12px; font:Arial, Helvetica, sans-serif; margin:25PX 0PX; background:#eee;}
 .botton{ color:#F00; cursor:pointer;}
 .mybody{width:600px; margin:0 auto; height:1500px; border:1px solid #ccc; padding:20px 25px; background:#fff}
 #cwxBg{ position:absolute; display:none; background:#000; width:100%; height:100%; left:0px; top:0px; z-index:1000;}
 #cwxWd{ position:absolute; display:none; border:10px solid #CCC; padding:10px;background:#FFF; z-index:1500;}
 #cwxCn{ background:#FFF; display:block;}
 .imgd{ width:400px; height:300px;}
</style>
</head>
<body>
<!--彈出窗-->
 <div class="mybody">
  <div class="botton" id="testClick">點擊測試</div>
 asdasdasdasdasdasdasd<br/>這里是一段文字哦!<div class="botton" id="testClick1">點擊測試</div>
 </div>
 <script type="text/javascript">
  C$('testClick').onclick = function(){
   var neirong = '<div><img src="http://www.dbjr.com.cn/images/logo.gif" class="imgd" /></div>';
   cwxbox.box.show(neirong);
  }
  C$('testClick1').onclick = function(){
   var neirong = '123456789132456789';
   cwxbox.box.show(neirong,3);
  }
  function C$(id){return document.getElementById(id);}
  //定義窗體對象
  var cwxbox = {};
  cwxbox.box = function(){
   var bg,wd,cn,ow,oh,o = true,time = null;
   return {
    show:function(c,t,w,h){
     if(o){
      bg = document.createElement('div'); bg.id = 'cwxBg'; 
      wd = document.createElement('div'); wd.id = 'cwxWd';
      cn = document.createElement('div'); cn.id = 'cwxCn';
      document.body.appendChild(bg);
      document.body.appendChild(wd);
      wd.appendChild(cn);
      bg.onclick = cwxbox.box.hide;
      window.onresize = this.init;
      window.onscroll = this.scrolls;
      o = false;
     }
     if(w && h){
      var inhtml = '<iframe src="'+ c +'" width="'+ w +'" height="'+ h +'" frameborder="0"></iframe>';
     }else{
      var inhtml  = c;
     }
     cn.innerHTML = inhtml;
     oh = this.getCss(wd,'offsetHeight');
     ow = this.getCss(wd,'offsetWidth');
     this.init();
     this.alpha(bg,50,1);
     this.drag(wd);
     if(t){
      time = setTimeout(function(){cwxbox.box.hide()},t*1000);
     }
    },
    hide:function(){
     cwxbox.box.alpha(wd,0,-1);
     clearTimeout(time);
    },
    init:function(){
     bg.style.height = cwxbox.page.total(1)+'px';
     bg.style.width = '';
     bg.style.width = cwxbox.page.total(0)+'px';
     var h = (cwxbox.page.height() - oh) /2;
     wd.style.top=(h+cwxbox.page.top())+'px';
     wd.style.left=(cwxbox.page.width() - ow)/2+'px';
    },
    scrolls:function(){
     var h = (cwxbox.page.height() - oh) /2;
     wd.style.top=(h+cwxbox.page.top())+'px';
    },
    alpha:function(e,a,d){
     clearInterval(e.ai);
     if(d==1){
      e.style.opacity=0; 
      e.style.filter='alpha(opacity=0)';
      e.style.display = 'block';
     }
     e.ai = setInterval(function(){cwxbox.box.ta(e,a,d)},40);
    },
    ta:function(e,a,d){
     var anum = Math.round(e.style.opacity*100);
     if(anum == a){
      clearInterval(e.ai);
      if(d == -1){
       e.style.display = 'none';
       if(e == wd){
        this.alpha(bg,0,-1);
       }
      }else{
       if(e == bg){
        this.alpha(wd,100,1);
       }
      }
     }else{
      var n = Math.ceil((anum+((a-anum)*.5)));
      n = n == 1 ? 0 : n;
      e.style.opacity=n/100;
      e.style.filter='alpha(opacity='+n+')';
     }
    },
    getCss:function(e,n){
     var e_style = e.currentStyle ? e.currentStyle : window.getComputedStyle(e,null);
     if(e_style.display === 'none'){
      var clonDom = e.cloneNode(true);
      clonDom.style.cssText = 'position:absolute; display:block; top:-3000px;';
      document.body.appendChild(clonDom);
      var wh = clonDom[n];
      clonDom.parentNode.removeChild(clonDom);
      return wh;
     }
     return e[n];
    },
    drag:function(e){
     var startX,startY,mouse;
     mouse = {
      mouseup:function(){
       if(e.releaseCapture)
       {
        e.onmousemove=null;
        e.onmouseup=null;
        e.releaseCapture();
       }else{
        document.removeEventListener("mousemove",mouse.mousemove,true);
        document.removeEventListener("mouseup",mouse.mouseup,true);
       }
      },
      mousemove:function(ev){
       var oEvent = ev||event;
       e.style.left = oEvent.clientX - startX + "px"; 
       e.style.top = oEvent.clientY - startY + "px"; 
      }
     }
     e.onmousedown = function(ev){
      var oEvent = ev||event;
      startX = oEvent.clientX - this.offsetLeft; 
      startY = oEvent.clientY - this.offsetTop;
      if(e.setCapture)
      {
       e.onmousemove= mouse.mousemove;
       e.onmouseup= mouse.mouseup;
       e.setCapture();
      }else{
       document.addEventListener("mousemove",mouse.mousemove,true);
       document.addEventListener("mouseup",mouse.mouseup,true);
      }
     } 
    }
   }
  }()
  cwxbox.page = function(){
   return{
    top:function(){return document.documentElement.scrollTop||document.body.scrollTop},
    width:function(){return self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth},
    height:function(){return self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},
    total:function(d){
     var b=document.body, e=document.documentElement;
     return d?Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.clientHeight,e.clientHeight)):
     Math.max(Math.max(b.scrollWidth,e.scrollWidth),Math.max(b.clientWidth,e.clientWidth))
    }
   } 
  }()
 </script>
</body>
</html>

希望本文所述對大家的JavaScript程序設(shè)計有所幫助。

相關(guān)文章

  • JS動態(tài)修改網(wǎng)頁body的背景色實例代碼

    JS動態(tài)修改網(wǎng)頁body的背景色實例代碼

    這篇文章主要介紹了JS動態(tài)修改網(wǎng)頁body的背景色實例代碼 ,需要的朋友可以參考下
    2017-10-10
  • JavaScript中數(shù)組sort()方法的基本使用與踩坑記錄

    JavaScript中數(shù)組sort()方法的基本使用與踩坑記錄

    : js中用方法sort()為數(shù)組排序,這篇文章主要給大家介紹了關(guān)于JavaScript中數(shù)組sort()方法的基本使用,sort()方法已經(jīng)可以滿足我們對數(shù)組的很多處理需求,需要的朋友可以參考下
    2021-06-06
  • IE11下CKEditor在Bootstrap Modal中下拉問題的解決

    IE11下CKEditor在Bootstrap Modal中下拉問題的解決

    這篇文章主要介紹了IE11下CKEditor在Bootstrap Modal中下拉問題的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • JavaScript實現(xiàn)的伸展收縮型菜單代碼

    JavaScript實現(xiàn)的伸展收縮型菜單代碼

    這篇文章主要介紹了JavaScript實現(xiàn)的伸展收縮型菜單代碼,可實現(xiàn)JavaScript響應(yīng)鼠標(biāo)事件動態(tài)遍歷及修改頁面元素屬性的功能,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-10-10
  • 聊一聊JS中this的指向問題

    聊一聊JS中this的指向問題

    這篇文章主要為大家詳細(xì)介紹了聊一聊JS中this的指向問題,幫助大家輕松了解JS中this的指向,感興趣的小伙伴們可以參考一下
    2016-06-06
  • JS去除字符串的空格增強版(可以去除中間的空格)

    JS去除字符串的空格增強版(可以去除中間的空格)

    之前發(fā)了不少了去除字符串空格的代碼,但都是去除開始與結(jié)尾的,下面的這段代碼可以去除中間的。
    2009-08-08
  • js+canvas繪制圖形驗證碼

    js+canvas繪制圖形驗證碼

    這篇文章主要為大家詳細(xì)介紹了js+canvas繪制圖形驗證碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • 對采用動態(tài)原型方式無法展示繼承機制得思考

    對采用動態(tài)原型方式無法展示繼承機制得思考

    今天看書,作者討論到能否采用動態(tài)原型方法展示繼承機制,給出的答案是:不能。原因是prototype對象的唯一性??聪旅娲a(這段代碼不正確,卻值得研究)
    2009-12-12
  • 如何改進(jìn)javascript代碼的性能

    如何改進(jìn)javascript代碼的性能

    在web應(yīng)用中,應(yīng)用了大量的Javascript,因此代碼的執(zhí)行效率變得尤為重要,也就是性能!為了提高JS的性能,我們應(yīng)該掌握一些基本的性能優(yōu)化方式,并讓它成為我們書寫代碼的習(xí)慣。下面介紹幾種優(yōu)化性能的方式,很多初學(xué)者甚至有經(jīng)驗的開發(fā)者也會忽略,希望對你有幫助
    2015-04-04
  • js中l(wèi)ess常用的方法小結(jié)

    js中l(wèi)ess常用的方法小結(jié)

    下面小編就為大家?guī)硪黄猨s中l(wèi)ess常用的方法小結(jié)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08

最新評論