이 기사의 예에서는 jQuery가 Div 드래그 및 키보드 제어의 포괄적인 효과를 구현하는 방법을 설명합니다. 참고할 수 있도록 모든 사람과 공유하세요. 구체적인 구현 방법은 다음과 같습니다. 코드 복사 코드는 다음과 같습니다. jQuery Div拖动+键盘控制综合效果 预览时看不到效果,刷新一下即可 <br> var msgObj = document.getElementById('text');<br> var posx = 0;<br> var posy = 0;<br> var moveable = false;<br> var MouseDownEvent = document.onmousedown;<br> var MouseMoveEvent = document.onmousemove;<br> var MouseUpEvent = document.onmouseup;<br> msgObj.onmousedown = function(evt) {<br> var evt = evt||window.event;<br> moveable = true; <br> posy = evt.clientY-parseInt(msgObj.style.top);<br> posx = evt.clientX-parseInt(msgObj.style.left);<br> document.onmousemove = function(evt) {<br> if (moveable) {<br> var evt = evt||window.event;<br> msgObj.style.left = evt.clientX - posx + "px";<br> msgObj.style.top = evt.clientY - posy + "px";<br> }<br> change();<br> };<br> document.onmouseup = function () { <br> if (moveable) { <br> document.onmousemove = MouseMoveEvent;<br> document.onmouseup = MouseUpEvent;<br> moveable = false; <br> posx = 0;<br> posy = 0;<br> } <br> };<br> }<br> var v=1;<br> var a=0.9;<br> var h=document.documentElement.clientHeight;<br> function scroll(){<br> var timer=setInterval(function(){<br> v +=a;<br> var top=(parseInt(msgObj.style.top)||0);<br> if(top+v>h-70){<br> if(v<2)clearInterval(timer);<br /> msgObj.style.top=h-70+"px";<br /> v=-v*0.5; <br /> }else{<br /> msgObj.style.top=top+v+"px";<br /> }<br /> change();<br /> },10);<br /> };<br /> $(document).keyup(function(e){<br /> var e = e || window.event ;<br /> if(e.which == 13){<br /> scroll(); <br /> }<br /> })<br /> var x = 4 ;<br /> var y = 4 ;<br /> function newpro(){<br /> var Height = document.documentElement.clientHeight ;<br /> var Width = document.documentElement.clientWidth ;<br /> var newobj = document.createElement('div');<br /> newobj.setAttribute('id','bigbox');<br /> newobj.style.position = 'absolute';<br /> newobj.style.left = 20 +"px";<br /> newobj.style.top = 80 +"px";<br /> newobj.style.height = Height/x +"px" ;<br /> newobj.style.width = Width/y +"px" ;<br /> newobj.style.borderWidth = 1+"px";<br /> newobj.style.borderColor = "#ff6500";<br /> newobj.style.borderStyle = 'solid' ;<br /> newobj.innerHTML='<div id="minbox"></div>';<br> Document.body.appendChild(newobj);<br> 변경();<br> }<br> 함수 변경(){<br> var minobj = document.getElementById('minbox');<br> minobj.style.position = '절대';<br> minobj.style.left = parsInt(msgObj.style.left)/x "px";<br> minobj.style.top = parsInt(msgObj.style.top)/y "px";<br> minobj.style.height = 20 "px" ;<br> minobj.style.width = 30 "px" ;<br> minobj.style.Background = "#F06";<br> }<br> window.onload = 함수(){<br> newpro();<br> }<br> <br> </본문><br> </div>