Detecting coordinates to pass to a Javascript func

Results 1 to 2 of 2

Thread: Detecting coordinates to pass to a Javascript func

  1. #1
    Willie Guest

    Default Detecting coordinates to pass to a Javascript func

    We are writing a calendar button function that we&#039d like to make portable. We need to pass the location of the button to the function so we can tell it where to pop up the calendar upon OnClick. Right now we are using absolute positioning and sending the coordinates of the absolute position. We don&#039t want everyone who uses the button on their page to have to use absolute positioning. Is there a way to detect the x,y coordinates of a button on an html page and pass those to the function? <BR><BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default RE: Detecting coordinates to pass to a Javascript

    it&#039s very possible - here&#039s some code - you&#039ll need to dissect it to make it work for you - it&#039s riped staright from one of my pages - the important properties are pageX and pageY and event.x etc...<BR><BR>jason<BR><BR>function displayCoords(evt) <BR> {<BR> if(document.layers)<BR> {<BR> var x = evt.pageX<BR> var y = evt.pageY<BR> var scrollX = x - 625<BR> var scrollY = y - 225<BR> document.forms[0].elements[0].value = x<BR> document.forms[0].elements[1].value = y<BR> document[&#039scrollCoords&#039].document.forms[0].elements[0].value = scrollX<BR> document[&#039scrollCoords&#039].document.forms[0].elements[1].value = scrollY<BR> }<BR> else if(document.all)<BR> {<BR> var x = window.event.x<BR> var y = window.event.y<BR> var scrollX = x - 625<BR> var scrollY = y - 225<BR> window.xVal.innerText = document.body.scrollLeft + x<BR> window.yVal.innerText = document.body.scrollTop + y<BR> window.xCoord.innerText = document.body.scrollLeft + scrollX<BR> window.yCoord.innerText = document.body.scrollTop + scrollY<BR> }<BR> // alert(&#039in scrollpad&#039)<BR> if(scrollX&#060;75&&scrollX&#062;-75&&scrollY&#060;75&&scrollY&#062;-75)<BR> {<BR> dX = parseInt(scrollX/5)<BR> dY = parseInt(scrollY/5)<BR> clearInterval(wintime)<BR> var func = <BR> wintime = setInterval("layerScroll(&#039scrollDiv&#039, dX, dY, 100)", 50) <BR> }<BR> else if(scrollX&#062;75&#124&#124scrollX&#060;-75&#124&#124scrollY&#062;75&#124&#124scrollY&#060 ;-75)<BR> {<BR> //alert(&#039stopping&#039)<BR> clearInterval(wintime)<BR> }<BR> return init()<BR> }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts