2、如何用鼠标任意拖动图片<body>
<script language="JavaScript">
<!--
whichEl = null;
function grabEl(e)
{
whichEl=event.srcElement; 
while (whichEl.id.indexOf("KBDRAG") == -1) { 
whichEl=whichEl.parentElement; 
if (whichEl == null) {  return;}   }
if (whichEl != activeEl) {
activeEl = whichEl; } 
whichEl.style.pixelLeft = whichEl.offsetLeft;
whichEl.style.pixelTop = whichEl.offsetTop; 
currentX = (event.clientX + document.body.scrollLeft);
currentY = (event.clientY + document.body.scrollTop); 
}function moveEl(e) {
if (whichEl == null) {return };newX = (event.clientX + document.body.scrollLeft);
newY = (event.clientY + document.body.scrollTop); 
distanceX = (newX - currentX);distanceY = (newY - currentY);currentX = newX;currentY = newY;whichEl.style.pixelLeft +=distanceX;whichEl.style.pixelTop +=distanceY;event.returnValue = false; }function checkEl() {if (whichEl!=null) 
{return false } 
}function dropEl() {whichEl = null; 
}function cursEl() {if (event.srcElement.id.indexOf("KBDRAG") != -1) 
{event.srcElement.style.cursor = "move" } 
}
document.onmousemove = moveEl;document.onselectstart = checkEl;document.onmouseover = cursEl;activeEl = document.all.dropKBDRAG; document.onmousedown = grabEl;document.onmouseup = dropEl; 
//--></script><div id='dropKBDRAG' style="position:absolute; left:50; top:50; width:50; height:50"><img src=1.gif></div></body>

解决方案 »

  1.   

    <script language="JavaScript1.2">
    function expand(per) {
    mypic.width=mypic.width*(1+per/100)
    mypic.height=mypic.height*(1+per/100)
    }
    function reduce(per) {
    mypic.width=mypic.width*(1-per/100)
    mypic.height=mypic.height*(1-per/100)
    }
    </script>
    </head><body>
    <img border="0" id="mypic" src="1.gif">
    <form>
    <input type=button onclick="expand(this.form.exp.value)" value=expand><input type=text name=exp size=3>percent<br>
    <input type=button onclick="reduce(this.form.rep.value)" value=reduce><input type=text name=rep size=3>percent
    </form>
    </body>