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

js+html+css實現(xiàn)鼠標移動div實例

 更新時間:2013年01月30日 18:05:15   作者:  
移動div對于很多的網(wǎng)有們來說是一件很熟悉的事了,本文老生長談,用js實現(xiàn)鼠標移動div,希望大伙們可以舉一反三,感興趣的朋友可以參考下,或許本文對你有所幫助
js:
復制代碼 代碼如下:

var posX;
var posY;
fdiv = document.getElementById("divBody");
document.getElementById("divHead").onmousedown=function(e)
{
if(!e) e = window.event; //IE
posX = e.clientX - parseInt(fdiv.style.left);
posY = e.clientY - parseInt(fdiv.style.top);
document.onmousemove = mousemove;
}
document.onmouseup = function()
{
document.onmousemove = null;
}
function mousemove(ev)
{
if(ev==null) ev = window.event;//IE
fdiv.style.left = (ev.clientX - posX) + "px";
fdiv.style.top = (ev.clientY - posY) + "px";
}

html:
復制代碼 代碼如下:

<div class="divBody" id="divBody" style="left: 29px; top: 14px;"> <!--這里要加style="left: 29px; top: 14px;" 否則有問題-->
<div class="divHead" id="divHead" style="cursor: move;">
</div>
<div class="content">
</div>
<div class="tail">
</div>
</div>

css:
復制代碼 代碼如下:

.divBody{
//margin-top:20px;
border: solid #CCC 1px;
width:500px;
height:400px;
position:relative;
z-index:0;
margin-left:auto;
margin-right:auto;
}
.divHead{
width:500px;
height:50px;
background-color:#CCC;
}
.content
{
width:500px;
height:300px;
}
.tail{
background:#CCC;
height:50px;
width:500px;
display:table-cell;
vertical-align:middle;
}

相關(guān)文章

最新評論

泰顺县| 连州市| 天镇县| 惠来县| 仪陇县| 巴东县| 抚顺县| 县级市| 江油市| 虎林市| 丁青县| 余江县| 宁蒗| 商南县| 田林县| 航空| 全州县| 温泉县| 保靖县| 温宿县| 明光市| 邻水| 富蕴县| 五台县| 横峰县| 永登县| 收藏| 金山区| 广饶县| 株洲县| 克拉玛依市| 上林县| 兴宁市| 江津市| 安多县| 新竹市| 申扎县| 文山县| 阳城县| 延川县| 宁化县|