最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Js可拖拽放大的層拖動特效實(shí)現(xiàn)方法

 更新時間:2015年02月25日 10:27:15   作者:代碼家園  
這篇文章主要介紹了Js可拖拽放大的層拖動特效實(shí)現(xiàn)方法,涉及javascript操作DOM元素及css樣式的技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實(shí)例講述了Js可拖拽放大的層拖動特效實(shí)現(xiàn)方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Js實(shí)現(xiàn)層拖動效果,還可以拖拽放大</title>
<style>
*{margin:0;padding:0;}
#zhezhao{
 width:100%;
 height:100%;
 background:#f00;
 filter:alpha(opacity:0);
 opacity:0;
 z-index:9999;
 position:absolute;
 top:0;
 left:0;
 display:none;
}
#div2{
 width:200px;
 height:200px;
 position:relative;
 background:#EEEEEE;
 border:1px solid #f00;
}
#div1{
 width:15px;
 height:15px;
 background:#99CC00;
 position:absolute;
 right:0px;
 bottom:0px;
 cursor:nw-resize;
 overflow:hidden;
 font-size:12px;
 text-align:center;
 line-height:15px;
 color:#FFFFFF;
 float:right;
 z-index:3;
}
#right{
 width:15px;
 height:100%;
 background:#f00;
 float:right;
 position:absolute;
 right:0;
 top:0;
 cursor:e-resize;
 overflow:hidden;
 filter:alpha(opacity:0);
 opacity:0;
 z-index:1;
}
#bottom{
 width:100%;
 height:15px;
 background:#f00;
 position:absolute;
 left:0;
 bottom:0;
 cursor:n-resize;
 overflow:hidden;
 filter:alpha(opacity:0);
 opacity:0;
 z-index:1;
}
#div2 p{
 padding:10px;
 line-height:24px;
 font-size:13px;
 text-indent:24px;
 color:#996600;
}
#div2 h2{
 width:100%;
 height:25px;
 line-height:25px;
 font-size:14px;
 background:#CC9900;
 color:#FFFFFF;
 text-indent:15px;
 cursor:move;
 overflow:hidden;
}
</style>
<script type="text/javascript">
window.onload=function()
{
 var oDiv=document.getElementById("div1");
 var oDiv2=document.getElementById("div2");
 var zhezhao=document.getElementById("zhezhao");
 var h2=oDiv2.getElementsByTagName("h2")[0];
 var right=document.getElementById("right");
 var bottom=document.getElementById("bottom");
 var mouseStart={};
 var divStart={};
 var rightStart={};
 var bottomStart={};
 //往右拽
 right.onmousedown=function(ev)
 {
  var oEvent=ev||event;
  mouseStart.x=oEvent.clientX;
  mouseStart.y=oEvent.clientY;
  rightStart.x=right.offsetLeft;
  if(right.setCapture)
  {
   right.onmousemove=doDrag1;
   right.onmouseup=stopDrag1;
   right.setCapture();
  }
  else
  {
   document.addEventListener("mousemove",doDrag1,true);
   document.addEventListener("mouseup",stopDrag1,true);
  }
 };
 function doDrag1(ev)
 {
  var oEvent=ev||event;
  var l=oEvent.clientX-mouseStart.x+rightStart.x;
  var w=l+oDiv.offsetWidth;
 
  if(w<oDiv.offsetWidth)
  {
   w=oDiv.offsetWidth;
  }
  else if(w>document.documentElement.clientWidth-oDiv2.offsetLeft)
  {
   w=document.documentElement.clientWidth-oDiv2.offsetLeft-2;
  }
  oDiv2.style.width=w+"px";
 };
 function stopDrag1()
 {
  if(right.releaseCapture)
  {
   right.onmousemove=null;
   right.onmouseup=null;
   right.releaseCapture();
  }
  else
  {
   document.removeEventListener("mousemove",doDrag1,true);
   document.removeEventListener("mouseup",stopDrag1,true);
  }
 };
 //往下拽
 bottom.onmousedown=function(ev)
 {
  var oEvent=ev||event;
  mouseStart.x=oEvent.clientX;
  mouseStart.y=oEvent.clientY;
  bottomStart.y=bottom.offsetTop;
  if(bottom.setCapture)
  {
   bottom.onmousemove=doDrag2;
   bottom.onmouseup=stopDrag2;
   bottom.setCapture();
  }
  else
  {
   document.addEventListener("mousemove",doDrag2,true);
   document.addEventListener("mouseup",stopDrag2,true);
  }
 };
 function doDrag2(ev)
 {
  var oEvent=ev||event;
  var t=oEvent.clientY-mouseStart.y+bottomStart.y;
  var h=t+oDiv.offsetHeight;
 
  if(h<oDiv.offsetHeight)
  {
   h=oDiv.offsetHeight;
  }
  else if(h>document.documentElement.clientHeight-oDiv2.offsetTop)
  {
   h=document.documentElement.clientHeight-oDiv2.offsetTop-2;
  }
 
  oDiv2.style.height=h+"px";
 };
 function stopDrag2()
 {
  if(bottom.releaseCapture)
  {
   bottom.onmousemove=null;
   bottom.onmouseup=null;
   bottom.releaseCapture();
  }
  else
  {
   document.removeEventListener("mousemove",doDrag2,true);
   document.removeEventListener("mouseup",stopDrag2,true);
  }
 };
 //往左右同時拽
 oDiv.onmousedown=function(ev)
 {
  var oEvent=ev||event;
  mouseStart.x=oEvent.clientX;
  mouseStart.y=oEvent.clientY;
  divStart.x=oDiv.offsetLeft;
  divStart.y=oDiv.offsetTop;
  if(oDiv.setCapture)
  {
   oDiv.onmousemove=doDrag;
   oDiv.onmouseup=stopDrag;
   oDiv.setCapture();
  }
  else
  {
   document.addEventListener("mousemove",doDrag,true);
   document.addEventListener("mouseup",stopDrag,true);
  }
  zhezhao.style.display='block';
 };
 function doDrag(ev)
 {
  var oEvent=ev||event;
  var l=oEvent.clientX-mouseStart.x+divStart.x;
  var t=oEvent.clientY-mouseStart.y+divStart.y;
 
 
  var w=l+oDiv.offsetWidth;
  var h=t+oDiv.offsetHeight;
 
  if(w<oDiv.offsetWidth)
  {
   w=oDiv.offsetWidth;
  }
  else if(w>document.documentElement.clientWidth-oDiv2.offsetLeft)
  {
   w=document.documentElement.clientWidth-oDiv2.offsetLeft-2;
  }
  if(h<oDiv.offsetHeight)
  {
   h=oDiv.offsetHeight;
  }
  else if(h>document.documentElement.clientHeight-oDiv2.offsetTop)
  {
   h=document.documentElement.clientHeight-oDiv2.offsetTop-2;
  }
 
  oDiv2.style.width=w+"px";
  oDiv2.style.height=h+"px";
 };
 function stopDrag()
 {
  if(oDiv.releaseCapture)
  {
   oDiv.onmousemove=null;
   oDiv.onmouseup=null;
   oDiv.releaseCapture();
  }
  else
  {
   document.removeEventListener("mousemove",doDrag,true);
   document.removeEventListener("mouseup",stopDrag,true);
  }
  zhezhao.style.display='none';
 };
 
 //h2完美拖拽
 h2.onmousedown=function(ev)
 {
  var oEvent=ev||event;
  mouseStart.x=oEvent.clientX;
  mouseStart.y=oEvent.clientY;
  divStart.x=oDiv2.offsetLeft;
  divStart.y=oDiv2.offsetTop;
 
  if(h2.setCapture)
  {
   h2.onmousemove=doDrag3;
   h2.onmouseup=stopDrag3;
   h2.setCapture();
  }
  else
  {
   document.addEventListener("mousemove",doDrag3,true);
   document.addEventListener("mouseup",stopDrag3,true);
  }
 
  zhezhao.style.display='block';
 };
 function doDrag3(ev)
 {
  var oEvent=ev||event;
  var l=oEvent.clientX-mouseStart.x+divStart.x;
  var t=oEvent.clientY-mouseStart.y+divStart.y;
  if(l<0)
  {
   l=0;
  }
  else if(l>document.documentElement.clientWidth-oDiv2.offsetWidth)
  {
   l=document.documentElement.clientWidth-oDiv2.offsetWidth;
  }
  if(t<0)
  {
   t=0;
  }
  else if(t>document.documentElement.clientHeight-oDiv2.offsetHeight)
  {
   t=document.documentElement.clientHeight-oDiv2.offsetHeight;
  }
  oDiv2.style.left=l+"px";
  oDiv2.style.top=t+"px";
 };
 function stopDrag3()
 {
  if(h2.releaseCapture)
  {
   h2.onmousemove=null;
   h2.onmouseup=null;
   h2.releaseCapture();
  }
  else
  {
   document.removeEventListener("mousemove",doDrag3,true);
   document.removeEventListener("mouseup",stopDrag3,true);
  }
 
  zhezhao.style.display='none';
 }
};
</script>
</head>
<body>
<div id="div2">
 <div style="width:100%; height:100%; overflow:hidden;">
 <h2>完美的拖拽</h2>
 <p>體驗(yàn)不錯的JavaScript網(wǎng)頁拖動,除了拖動,還可拖動放大,像Windows窗口一樣被放大或縮小,只要按住層的右下角,就可以收放自如的放大或縮小。想使用的朋友,可將代碼里的Js封裝成類,從外部引入想必更合理些。'</p>
 <div id="right"></div>
 <div id="div1">拖</div>
 <div id="bottom"></div>
 </div>
</div>
<div id="zhezhao"></div>
</body>
</html>

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

相關(guān)文章

  • 自己的js工具 Cookie 封裝

    自己的js工具 Cookie 封裝

    有些時候我們的web程序需要利用cookie來實(shí)現(xiàn)一些功能,很多時候我們并不需要非得用服務(wù)端來操作cookie,因?yàn)閖s可以也操作cookie.
    2009-08-08
  • JavaScript實(shí)現(xiàn)矩形塊大小任意縮放

    JavaScript實(shí)現(xiàn)矩形塊大小任意縮放

    這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)矩形塊大小任意縮放,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • 詳解ES6 Symbol 的用途

    詳解ES6 Symbol 的用途

    Symbol 唯一的用途就是標(biāo)識對象屬性,表明對象支持的功能。 這篇文章給大家介紹ES6 Symbol 的用途,感興趣的朋友跟隨小編一起看看吧
    2018-10-10
  • js中匿名函數(shù)的創(chuàng)建與調(diào)用方法分析

    js中匿名函數(shù)的創(chuàng)建與調(diào)用方法分析

    這篇文章主要介紹了js中匿名函數(shù)的創(chuàng)建與調(diào)用方法,詳細(xì)分析了匿名函數(shù)的原理與用法,以及閉包的原理分析,非常具有實(shí)用價值,需要的朋友可以參考下
    2014-12-12
  • js實(shí)現(xiàn)圖片上傳預(yù)覽原理分析

    js實(shí)現(xiàn)圖片上傳預(yù)覽原理分析

    這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)圖片上傳預(yù)覽的原理,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • html5+CSS 實(shí)現(xiàn)禁止IOS長按復(fù)制粘貼功能

    html5+CSS 實(shí)現(xiàn)禁止IOS長按復(fù)制粘貼功能

    因?yàn)樵谝苿佣薃PP需要實(shí)現(xiàn)長按執(zhí)行別的事件,但是在iOS系統(tǒng)有默認(rèn)的長按選擇復(fù)制粘貼。禁止在網(wǎng)上找了很多資料,下面小編給大家分享解決方案,一起看看吧
    2016-12-12
  • 微信小程序如何實(shí)現(xiàn)數(shù)據(jù)共享與方法共享詳解

    微信小程序如何實(shí)現(xiàn)數(shù)據(jù)共享與方法共享詳解

    這篇文章主要給大家介紹了關(guān)于微信小程序如何實(shí)現(xiàn)數(shù)據(jù)共享與方法共享的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2022-01-01
  • Web技術(shù)實(shí)現(xiàn)移動監(jiān)測的介紹

    Web技術(shù)實(shí)現(xiàn)移動監(jiān)測的介紹

    移動偵測,一般也叫運(yùn)動檢測,常用于無人值守監(jiān)控錄像和自動報警。通過攝像頭按照不同幀率采集得到的圖像會被 CPU 按照一定算法進(jìn)行計算和比較,當(dāng)畫面有變化時,如有人走過,鏡頭被移動,計算比較結(jié)果得出的數(shù)字會超過閾值并指示系統(tǒng)能自動作出相應(yīng)的處理
    2017-09-09
  • 圖解JavaScript作用域鏈底層原理

    圖解JavaScript作用域鏈底層原理

    當(dāng)代碼在一個環(huán)境中執(zhí)行時,會創(chuàng)建變量對象的一個作用域鏈,作用域鏈的用途是保證對執(zhí)行環(huán)境有權(quán)訪問的所有變量和函數(shù)的有序訪問,下面這篇文章主要給大家介紹了關(guān)于JavaScript作用域鏈底層原理的相關(guān)資料,需要的朋友可以參考下
    2021-11-11
  • cocos2dx+lua實(shí)現(xiàn)橡皮擦功能

    cocos2dx+lua實(shí)現(xiàn)橡皮擦功能

    這篇文章主要為大家詳細(xì)介紹了cocos2dx+lua實(shí)現(xiàn)橡皮擦功能,類似刮刮樂效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-12-12

最新評論

澄迈县| 连南| 嘉禾县| 浦东新区| 六枝特区| 睢宁县| 崇信县| 绥宁县| 昆山市| 乌兰县| 瑞丽市| 京山县| 灵武市| 高青县| 阿荣旗| 清远市| 德钦县| 于田县| 门头沟区| 博乐市| 灌南县| 元江| 含山县| 元谋县| 通渭县| 蓬溪县| 浦北县| 沅陵县| 临泉县| 嘉荫县| 抚宁县| 囊谦县| 伊吾县| 沁阳市| 邯郸县| 浦县| 宿迁市| 留坝县| 洛川县| 许昌市| 博乐市|