Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

?
Lv 5

How to display var data from javascript on html page?

Hello,

I am working on a personal site with very limited knowledge of html.

I came across a javascript which magnifies a portion of an image that the mouse is hovering over. The script works by using both a small and large version of the image and tracking the mouse coordinates to give a magnifying glass effect.

http://cssdeck.com/labs/magnifying-glass...

I'm trying to implement this function into my page with the added function of displaying the real time coordinates of the mouse while it's over the image. I've tried using demo scripts of this function, but the coordinates do not track in real time in conjunction with the magnifying effect. It will freeze on the coordinates of the image moments before the magnifying effect turns on.

Seeing as the magnifying javascript is already tracking the mouse coordinates of the large native image in realtime, I would like to simply extract that data and display the current x and y coords somewhere on my html page. How would I go about doing this?

Any help would be greatly appreciated.

Thank you in advance.

2 Answers

Relevance
  • Me2
    Lv 7
    4 years ago
    Favorite Answer

    Define a the spot on the web page to display the values,

    <div id="x-y-coords"></div>

    At a point in the Javascript where the coordinates are most recently updated, include code similar to this to display them.

    document.getElementById( "x-y-coords").innerHTML = "x=" + xcoord + " y=" + ycoord

  • ?
    Lv 7
    4 years ago

    Working example as suggested by Me2.

    http://cssdeck.com/labs/eusv0ui9

Still have questions? Get your answers by asking now.