123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- function mouseCoords(ev){
- if(ev.pageX || ev.pageY){
- return {x:ev.pageX, y:ev.pageY};
- }
- if(ev.clientX || ev.clientY) {
- return {x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
- y:ev.clientY + document.body.scrollTop - document.body.clientTop
- };
- }
- return false;
- }
- function getMouseOffset(target, ev){
- ev = ev || window.event;
- var docPos = getPosition(target);
- var mousePos = mouseCoords(ev);
- //alert(mousePos.x+" "+mousePos.y);
- return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
- }
- function getPosition(e){
- var left = 0;
- var top = 0;
- while (e.offsetParent){
- //alert("x:"+e.offsetLeft+" y:"+e.offsetTop+" "+e.outerHTML);
- try{
- left += e.offsetLeft;
- top += e.offsetTop-e.scrollTop;
- }catch(ev){}
- e = e.offsetParent;
- }
- try{
- left += e.offsetLeft;
- top += e.offsetTop;
- }catch(ev){}
- return {x:left, y:top};
- }
- function Mouse() {
- this.checkRClick = function checkRClick (e) {
- if (!e)e = window.event;
- if ((e.button && e.button == 2) || (e.which && e.which == 3)) {
- return true;
- }else{
- return false;
- }
- }
-
- this.coords = function coords(ev){
- if(ev.pageX || ev.pageY){
- return {x:ev.pageX, y:ev.pageY};
- }
- if(ev.clientX || ev.clientY) {
- return {x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
- y:ev.clientY + document.body.scrollTop - document.body.clientTop
- };
- }
- return false;
- }
- }
- var Mouse = new Mouse();
|