js 捕获鼠标事件
- function drag(overFlow,title){
- title.onmousedown = function(evt){
- var doc = document;
- var evt = evt || window.event;
- var x = evt.offsetX?evt.offsetX:evt.layerX;
- var y = evt.offsetY?evt.offsetY:evt.layerY;
- if(overFlow.setCapture){
- overFlow.setCapture();
- }else if(window.captureEvents){
- window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
- }
- doc.onmousemove = function(evt){
- evt = evt || window.event;
- var xPosition = evt.pageX || evt.clientX;
- var yPosition = evt.pageY || evt.clientY;
- var newX = xPosition - x;
- var newY = yPosition - y;
- overFlow.style.left = newX;
- overFlow.style.top = newY;
- };
- doc.onmouseup = function(){
- if(overFlow.releaseCapture){
- overFlow.releaseCapture();
- }else if(window.captureEvents){
- window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
- }
- doc.onmousemove=null;
- doc.onmouseup=null;
- };
- };
- }
把学习一种技术一直坚持下去。