所以我创建了一个 erb 块,它遍历每个图像的坐标,然后在给定坐标处为每个图像显示 div.tagged。在这种特殊情况下,该块遍历 2 个图像,每个图像显示一次 div.tagged,但是每个图像的 div.tagged 位置相同。有人对为什么有任何想法吗?这是生成的HTML
erb 块
<div class="container">
<% if @new_manual.present? %>
<% @new_manual.steps.each do |step| %>
<% i_connection = Contact.find(step.input_contact) %>
<span class="i_connection" data-pos-x="<%= i_connection.pos_x %>" data-pos-y="<%= i_connection.pos_y %>" data-pos-width="<%= i_connection.pos_width %>" data-pos-height="<%= i_connection.pos_height %>"> </span>
<div class="image_panel"><br>
<%= image_tag(i_connection.image.image.url(:large)) %>
<div class='planetmap'></div>
</div>
<% end %>
<% end %>
</div>
jQuery
$(document).ready(function(){
$("span.i_connection").each(function() {
var pos_width = $(this).data('pos-width');
var pos_height = $(this).data('pos-height');
var xpos = $(this).data('pos-x');
var ypos = $(this).data('pos-y');
$(".tagged_box").css("display","block");
$(".tagged").css("border","5px solid red");
$('.planetmap').append('<div class="tagged" style="width:'+pos_width+'px;height:'+pos_height+'px;left:'+xpos+'px;top:'+ypos+'px;" ><div class="tagged_box" style="width:'+pos_width+'px;height:'+
pos_height+'px;" ></div>')
}); //END OF SPAN.CONNECTION ITERATION
}); //END OF JQUERY