Jump to content

Recommended Posts

Let's suppose I have a hundred images on a page.

<a href="page.php?x=1895&y=2015"><img style='background:url(images/tile_2.png)' class='xyz' data-alt-src='images/X.png' data-name='   ' src="images/tile_2.png" /></a>

When on hover, the image URL is changed to the alt-src and the data-name is then displayed in an TD.

 

Now, suppose I wanted to alter the IMG tag to become something similar to:

<img style='background:url(images/tile_2.png)' class='xyz' data-alt-src='images/X.png' data-name='   ' data-connection='2' data-id='15' data-lineColor='#005500' src="images/tile_2.png" />

I'd then want to draw a straight line in the lineColor attribute connecting the above image to the image(s) that contain the same data-connection attribute.

 

Or, I could always assign the images an x, y coord system and reference them as data-connectionX = '15' data-connectionY='16' data-x='19' data-y='25' and have it draw the lines to the images that contain the same data-connectionX and data-connectionY attributes.

 

Cannot figure out how to do that...

 

I tried using HTML5 canvas, but when I tried to even draw a line on the canvas while shifting HTML (the images) over the canvas, the images covered the canvas and line drawn. When I tried to change the z-index of the canvas, it worked except that the canvas covered over the HTML and made the existing on-hover image changes not work, as well I needed to define the absolute locations for the start and end points of the line, and with my code being dynamic and able to be changed by altering GET variables, I need something that calculates the location of the images automatically.

I've found regular JS examples of drawing lines, but they all rely on knowing the exact points to draw from...is there any way to do this by having the exact points be calculated by the JS and not needing to be hard-coded in? With the on-hover displaying the drawn lines?

Link to comment
https://forums.phpfreaks.com/topic/282784-draw-line-between-to-elements-on-hover/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.