Solved

HTML5 + get image location inside container

Posted on 2013-01-03
1
406 Views
Last Modified: 2013-01-24
Is there a way to loop through all the images inside a container and get their location, the X and Y of each image?

I want to get the coordinates from a click of a button, the images are draggable, so once the button is clicked i want to see this info.
0
Comment
Question by:dkilby
1 Comment
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 38742595
By way of example, you could add a <ol> and a button to your page:

<input type="button" id="printPositions" value="Print Image Positions" />
<ol id="positions"></ol>

Then use jquery to print out the positions of each image on the page. This would be X and Y coordinates relative to the document edges. You could also make it relative to a container's edges.
$(document).ready(function(){
	$("#printPositions").bind("click", function(){
		var listItem, liText;
		$("img").each(function(i){
			var imgPos = $(this).offset();
			listItem = document.createElement("li");
			liText = document.createTextNode("X=" + imgPos.left + " Y=" + imgPos.top);
			listItem.appendChild(liText);
			$("#positions").append(listItem);
		});
	});
});
</script>

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to dynamically set the form action using jQuery.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question