<style> div{position:absolute;} </style> <script type="text/javascript"> function $(i){return document.getElementById(i)} var Bj={ init:function(){} ,down:function(e){this.d = true;} ,up:function(){this.d = false;} ,move:function(e){ e = e || window.event; if(this.d){ $("Cl1").style.left = e.clientX-50+ "px"; $("Cl1").style.top = e.clientY-50+ "px"; if(e.clientX>parseInt($("Cl2").style.left)&&e.clientX<(parseInt($("Cl2").style.left)+parseInt($("Cl2").style.width))&&e.clientY>parseInt($("Cl2").style.top)&&e.clientY<(parseInt($("Cl2").style.top)+parseInt($("Cl2").style.height))) $("Cl2").style.background ="#FF0000"; else $("Cl2").style.background ="#00FF00"; } } } </script> </HEAD> <BODY> <div id=Cl1 onMouseMove=Bj.move(event,this) onMouseDown=Bj.down(event,this) onmouseup='Bj.up()' style="left:100px; top:100px;width:100px;height:100px;border:1px solid #000000; background:#666666;z-index:10">拖我</div> <div id=Cl2 onMouseMove=Bj.move(event,this) onMouseDown=Bj.down(event,this) onmouseup='Bj.up()' style="left:100px; top:220px;width:200px;height:100px;border:1px solid #000000; background:#00FF00">到这里</div>
javascript 拖动
猜你喜欢
转载自soundhorizon.iteye.com/blog/1454807
今日推荐
周排行