可以用鼠标拖放图片位置的代码
答案:1 悬赏:40 手机版
解决时间 2021-07-25 18:23
- 提问者网友:最爱你的唇
- 2021-07-24 23:10
可以用鼠标拖放图片位置的代码是什么
最佳答案
- 五星知识达人网友:几近狂妄
- 2021-07-25 00:05
<html>
<head>
<title>网页特效||---能用鼠标拖放的图片</title>
</head><body onload="init()">
<!--用<body onload="init()">替换原来的<body>-->
<!--将以下代码加入HTML的<Body></Body>之间-->
<SCRIPT language=JavaScript>
<!--
drag = 0
move = 0
function init() {
window.document.onmousemove = mouseMove
window.document.onmousedown = mouseDown
window.document.onmouseup = mouseUp
window.document.ondragstart = mouseStop
}
function mouseDown() {
if (drag) {
clickleft = window.event.x - parseInt(dragObj.style.left)
clicktop = window.event.y - parseInt(dragObj.style.top)
dragObj.style.zIndex += 1
move = 1
}
}
function mouseStop() {
window.event.returnValue = false
}
function mouseMove() {
if (move) {
dragObj.style.left = window.event.x - clickleft
dragObj.style.top = window.event.y - clicktop
}
}
function mouseUp() {
move = 0
}
//-->
</SCRIPT>
<DIV id=block1 onmouseout=drag=0 onmouseover="dragObj=block1; drag=1;"
style="HEIGHT: 90px; LEFT: 200px; POSITION: absolute; TOP: 200px; WIDTH: 90px">
<IMG
alt="" border=0
src=" http://www.baidu.com/img/baidu_logo.gif" border="0" width="85" height="55">
</body></html>
<head>
<title>网页特效||---能用鼠标拖放的图片</title>
</head><body onload="init()">
<!--用<body onload="init()">替换原来的<body>-->
<!--将以下代码加入HTML的<Body></Body>之间-->
<SCRIPT language=JavaScript>
<!--
drag = 0
move = 0
function init() {
window.document.onmousemove = mouseMove
window.document.onmousedown = mouseDown
window.document.onmouseup = mouseUp
window.document.ondragstart = mouseStop
}
function mouseDown() {
if (drag) {
clickleft = window.event.x - parseInt(dragObj.style.left)
clicktop = window.event.y - parseInt(dragObj.style.top)
dragObj.style.zIndex += 1
move = 1
}
}
function mouseStop() {
window.event.returnValue = false
}
function mouseMove() {
if (move) {
dragObj.style.left = window.event.x - clickleft
dragObj.style.top = window.event.y - clicktop
}
}
function mouseUp() {
move = 0
}
//-->
</SCRIPT>
<DIV id=block1 onmouseout=drag=0 onmouseover="dragObj=block1; drag=1;"
style="HEIGHT: 90px; LEFT: 200px; POSITION: absolute; TOP: 200px; WIDTH: 90px">
<IMG
alt="" border=0
src=" http://www.baidu.com/img/baidu_logo.gif" border="0" width="85" height="55">
</body></html>
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯