在Dreamweaver中,怎么实现图片可以随便移动
5个回答
2015-12-26 · 知道合伙人互联网行家
关注
展开全部
在网页中插入一个apdiv,将图片插入到apdiv中。
切换到拆分视图,选中body标签,调出行为面板。
给body标签添加拖动ap元素行为,设置好参数后就可以实现效果
实例代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "地址/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="地址/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>123</title>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
left:338px;
top:27px;
width:168px;
height:123px;
z-index:1;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_scanStyles(obj, prop) { //v9.0
var inlineStyle = null; var ccProp = prop; var dash = ccProp.indexOf("-");
while (dash != -1){ccProp = ccProp.substring(0, dash) + ccProp.substring(dash+1,dash+2).toUpperCase() + ccProp.substring(dash+2); dash = ccProp.indexOf("-");}
inlineStyle = eval("obj.style." + ccProp);
if(inlineStyle) return inlineStyle;
var ss = document.styleSheets;
for (var x = 0; x < ss.length; x++) { var rules = ss[x].cssRules;
for (var y = 0; y < rules.length; y++) { var z = rules[y].style;
if(z[prop] && (rules[y].selectorText == '*[ID"' + obj.id + '"]' || rules[y].selectorText == '#' + obj.id)) {
return z[prop];
} } } return "";
}
function MM_getProp(obj, prop) { //v8.0
if (!obj) return ("");
if (prop == "L") return obj.offsetLeft;
else if (prop == "T") return obj.offsetTop;
else if (prop == "W") return obj.offsetWidth;
else if (prop == "H") return obj.offsetHeight;
else {
if (typeof(window.getComputedStyle) == "undefined") {
if (typeof(obj.currentStyle) == "undefined"){
if (prop == "P") return MM_scanStyles(obj,"position");
else if (prop == "Z") return MM_scanStyles(obj,"z-index");
else if (prop == "V") return MM_scanStyles(obj,"visibility");
} else {
if (prop == "P") return obj.currentStyle.position;
else if (prop == "Z") return obj.currentStyle.zIndex;
else if (prop == "V") return obj.currentStyle.visibility;
}
} else {
if (prop == "P") return window.getComputedStyle(obj,null).getPropertyValue("position");
else if (prop == "Z") return window.getComputedStyle(obj,null).getPropertyValue("z-index");
else if (prop == "V") return window.getComputedStyle(obj,null).getPropertyValue("visibility");
}
}
}
function MM_dragLayer(objId,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v9.01
//Copyright 2005-2006 Adobe Macromedia Software LLC and its licensors. All rights reserved.
var i,j,aLayer,retVal,curDrag=null,curLeft,curTop,IE=document.all;
var NS=(!IE&&document.getElementById); if (!IE && !NS) return false;
retVal = true; if(IE && event) event.returnValue = true;
if (MM_dragLayer.arguments.length > 1) {
curDrag = document.getElementById(objId); if (!curDrag) return false;
if (!document.allLayers) { document.allLayers = new Array();
with (document){ if (NS) { var spns = getElementsByTagName("span"); var all = getElementsByTagName("div");
for (i=0;i<spns.length;i++) if (MM_getProp(spns[i],'P')) allLayers[allLayers.length]=spns[i];}
for (i=0;i<all.length;i++) {
if (MM_getProp(all[i],'P')) allLayers[allLayers.length]=all[i];
}
} }
curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
curDrag.MM_oldZ = MM_getProp(curDrag,'Z');
curLeft = MM_getProp(curDrag,'L');
if (String(curLeft)=="NaN") curLeft=0; curDrag.MM_startL = curLeft;
curTop = MM_getProp(curDrag,'T');
if (String(curTop)=="NaN") curTop=0; curDrag.MM_startT = curTop;
curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop-cU;
curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop+cD;
curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
} else {
切换到拆分视图,选中body标签,调出行为面板。
给body标签添加拖动ap元素行为,设置好参数后就可以实现效果
实例代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "地址/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="地址/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>123</title>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
left:338px;
top:27px;
width:168px;
height:123px;
z-index:1;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_scanStyles(obj, prop) { //v9.0
var inlineStyle = null; var ccProp = prop; var dash = ccProp.indexOf("-");
while (dash != -1){ccProp = ccProp.substring(0, dash) + ccProp.substring(dash+1,dash+2).toUpperCase() + ccProp.substring(dash+2); dash = ccProp.indexOf("-");}
inlineStyle = eval("obj.style." + ccProp);
if(inlineStyle) return inlineStyle;
var ss = document.styleSheets;
for (var x = 0; x < ss.length; x++) { var rules = ss[x].cssRules;
for (var y = 0; y < rules.length; y++) { var z = rules[y].style;
if(z[prop] && (rules[y].selectorText == '*[ID"' + obj.id + '"]' || rules[y].selectorText == '#' + obj.id)) {
return z[prop];
} } } return "";
}
function MM_getProp(obj, prop) { //v8.0
if (!obj) return ("");
if (prop == "L") return obj.offsetLeft;
else if (prop == "T") return obj.offsetTop;
else if (prop == "W") return obj.offsetWidth;
else if (prop == "H") return obj.offsetHeight;
else {
if (typeof(window.getComputedStyle) == "undefined") {
if (typeof(obj.currentStyle) == "undefined"){
if (prop == "P") return MM_scanStyles(obj,"position");
else if (prop == "Z") return MM_scanStyles(obj,"z-index");
else if (prop == "V") return MM_scanStyles(obj,"visibility");
} else {
if (prop == "P") return obj.currentStyle.position;
else if (prop == "Z") return obj.currentStyle.zIndex;
else if (prop == "V") return obj.currentStyle.visibility;
}
} else {
if (prop == "P") return window.getComputedStyle(obj,null).getPropertyValue("position");
else if (prop == "Z") return window.getComputedStyle(obj,null).getPropertyValue("z-index");
else if (prop == "V") return window.getComputedStyle(obj,null).getPropertyValue("visibility");
}
}
}
function MM_dragLayer(objId,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v9.01
//Copyright 2005-2006 Adobe Macromedia Software LLC and its licensors. All rights reserved.
var i,j,aLayer,retVal,curDrag=null,curLeft,curTop,IE=document.all;
var NS=(!IE&&document.getElementById); if (!IE && !NS) return false;
retVal = true; if(IE && event) event.returnValue = true;
if (MM_dragLayer.arguments.length > 1) {
curDrag = document.getElementById(objId); if (!curDrag) return false;
if (!document.allLayers) { document.allLayers = new Array();
with (document){ if (NS) { var spns = getElementsByTagName("span"); var all = getElementsByTagName("div");
for (i=0;i<spns.length;i++) if (MM_getProp(spns[i],'P')) allLayers[allLayers.length]=spns[i];}
for (i=0;i<all.length;i++) {
if (MM_getProp(all[i],'P')) allLayers[allLayers.length]=all[i];
}
} }
curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
curDrag.MM_oldZ = MM_getProp(curDrag,'Z');
curLeft = MM_getProp(curDrag,'L');
if (String(curLeft)=="NaN") curLeft=0; curDrag.MM_startL = curLeft;
curTop = MM_getProp(curDrag,'T');
if (String(curTop)=="NaN") curTop=0; curDrag.MM_startT = curTop;
curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop-cU;
curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop+cD;
curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
} else {
展开全部
======================代码可用,亲自测试过了
<html>
<head>
<meta charset='utf-8'>
<title>图片随便移动</title>
</head>
<body>
<div id="img" style="position:absolute;z-index=99;border:10px solid green;width:150px;height:150px;"> 我会随便移动 !
</div>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var xPos = document.body.clientWidth-20;
var yPos = document.body.clientHeight/2;
var step = 2;
var delay = 5;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
var img = document.getElementById('img');
img.style.top = yPos;
function changePos() {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = img.offsetHeight;
Woffset = img.offsetWidth;
img.style.left = xPos + document.body.scrollLeft;
img.style.top = yPos + document.body.scrollTop;
if (yon) {
yPos = yPos + step;
}else {
yPos = yPos - step;
}
if (yPos < 0) {
yon = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset)) {
yon = 0;
yPos = (height - Hoffset);
}
if (xon) {
xPos = xPos + step;
}else {
xPos = xPos - step;
}
if (xPos < 0) {
xon = 1;
xPos = 0;
}
if (xPos >= (width - Woffset)) {
xon = 0;
xPos = (width - Woffset);
}
}
function start() {
img.visibility = "visible";
interval = setInterval('changePos()', delay);
}
start();
img.onmouseover = function() {
clearInterval(interval);
interval = null;
}
img.onmouseout = function() {
interval = setInterval('changePos()', delay);
}
// End -->
</script>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
什么意思?你是要让做好的网页在浏览器里可以用鼠标拖动上面的图片吗?还是说在Dw设计器里直接拖动图片?
追问
在Dw设计器里直接拖动图片呀,怎么实现呢
追答
哦,这个简单,你用Dw的层进行布局,把图片插入到层里,然后拖动层,图片就跟着移动了,可以随意拖动的,层的高度和宽度设置和图片一样大小,层的左上角会有一个"#"号标记,点井号拖动
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1 点插入层
2 加入图片
3 工具栏窗口 点时间轴
4在时间轴编辑图片轨迹
2 加入图片
3 工具栏窗口 点时间轴
4在时间轴编辑图片轨迹
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把图片放入层中:在代码中加入<div><img src="图片地址" /></div>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |