html如何使图片移动

html如何使图片移动

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<body>标签中,输入html代码:<img style="margin-top: 100px" src="small2.png" />。

3、浏览器运行index.html页面,此时图片被向下移动了100px。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-10-08
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>陇县地图详细</title>
<style>
#win{position:absolute;left:943px;top:62px;width:80px;border:1px solid #000;}
.title{width:80px;background:#000;height:20px;color:#fff;cursor:hand;}
</style>
<script>
var x0=0,y0=0,x1=0,y1=0;
var moveable=false;
//开始拖动;
function startDrag(obj){
if(event.button==1){
obj.setCapture();
var win = obj.parentNode;
x0 = event.clientX;
y0 = event.clientY;
x1 = parseInt(win.offsetLeft);
y1 = parseInt(win.offsetTop);
moveable = true;
}
}
//拖动;
function drag(obj){
if(moveable){
var win = obj.parentNode;
win.style.left = x1 + event.clientX - x0;
win.style.top = y1 + event.clientY - y0;
}
}
//停止拖动;
function stopDrag(obj){
if(moveable){
obj.releaseCapture();
moveable = false;
}
}
</script>
</head>
<body>
<div id="win">
<div class="title" onMouseDown="startDrag(this)" onMouseUp="stopDrag(this)" onMouseMove="drag(this)"><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"/></div>
</div>
</body>
</html>本回答被提问者采纳