Solved

HTML5 + get image location inside container

Posted on 2013-01-03
1
411 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

734 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