Answer the question
In order to leave comments, you need to log in
How to anchor a div on a page that is rendered in an iframe?
On the site, the page is displayed in an iframe with scrolls. It is necessary, after drag & drop, to fix the div at a certain place in the country, which is in the iframe. How to do it? Google didn't help.
in src iframe the address is added dynamically. Those. The user can enter absolutely any address.
Answer the question
In order to leave comments, you need to log in
The problem statement is not entirely clear. As I understand it, you need to:
1) Add a div to the iframe when drag'n'drop
2) Position:absolute must be written in the styles of the div (relative to the parent, i.e. frame)
3) Assign the position to the div (top and left)
What something like this:
//создаем iframe, в принцепи не важно как ты его создаешь, главное присвоить ему имя
var iframe = document.createElement("iframe");
//создаем див и назначаем стили
var div = iframe.document.createElement("div");
div.style.position = "absolute";
div.style.top = x+"px";
div.style.left = y+"px";
iframe.document.body.appendChild(div);
Let's say:
your iframe (map) is 1200x1200, and its visible part is 800x600. The div pointer (label) is just position:absolute but its margin is the x and y coordinates (0-1200 and 0-1200) that this element's drag-n-drop assigns to it.
Copy Source | Copy HTML
- $('#LocationMap').click(function(e){
- var x = e.pageX - this.offsetLeft;
- var y = e.pageY - this.offsetTop;
- $("input[name=location_x]").val(x);
- $("input[name=location_y]").val(y);
- $("#Flag").css({"margin-left": ""+x+"px"}).css({"margin-top": ""+y+"px"});
- });
-
Didn't quite understand what you want, but it's possible: position:absolute; help you?
If the iframe is from the same domain, then you can add your own label with position:absolute there (inside the document in the iframe), as they say above. Then it will normally scroll along with the map. You can find out the coordinates after drag'n'drop through the scrollTop/scrollLeft of the document in the iframe and the position of the iframe on the page.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question