国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

js+html+css實現鼠標移動div實例

2024-05-06 14:19:43
字體:
來源:轉載
供稿:網友
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;
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 云龙县| 新巴尔虎左旗| 迁西县| 青岛市| 洪泽县| 连山| 汉沽区| 秦皇岛市| 桑日县| 三都| 霍邱县| 滨州市| 喀什市| 霍林郭勒市| 阜城县| 卓资县| 宁都县| 崇仁县| 平邑县| 信丰县| 游戏| 托里县| 博爱县| 镇坪县| 芮城县| 南召县| 稻城县| 体育| 赣州市| 邹平县| 宁化县| 唐河县| 化德县| 稻城县| 卫辉市| 崇仁县| 岑溪市| 敖汉旗| 南郑县| 连江县| 横山县|