【发布时间】:2013-07-21 14:00:21
【问题描述】:
所以我创建了一个遍历一组图像的 erb 块,然后在给定坐标处为每个图像显示 div.tagged。在这种特殊情况下,块会遍历 1 个图像,但是 div.tagged 不会显示在页面上。当我检查元素时 .tagged 存在,但实际上并未显示。有人对为什么有任何想法吗? Here is the HTML that is generated.And here is a screen shot of the inspected element
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 %>" data-image=> </span>
<br>
<div class="image_panel">
<%= image_tag(i_connection.image.image.url(:large)) %>
<div class='i_connection'></div>
</div>
<% end %>
<% end %>
</div>
jQuery:
<script type="text/javascript">
$(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");
$('.i_connection').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;" style="position:absolute;"></div>')
});
});
CSS:
.i_connection div{
display:block;
position:absolute;
}
.image_panel{
float:left;
width:600px;
position:relative;
}
.image_panel img{
left:0;top:0px;
max-width: 600px;
overflow: hidden;
}
【问题讨论】:
-
您是说 div 标记未显示,但您正在提供其他 div 的 css 代码。我也会为
taggeddiv 放置 css -
您应该能够比我们通过阅读您的代码更容易地进行调试。使用 chrome 检查,您可以编辑 CSS 和 HTML 属性,玩转直到可以显示它,考虑
z-index,也许? -
我把它放在jsfiddle 中,但我在你的span
.i_connection标签中看不到任何东西。 -
标记的 css 在 jQuery 中的样式是正确的,我尝试使用 z-index 和绝对定位,仍然没有运气。
-
@Yasky 正是我的问题。如果您检查图像,.tagged 是否存在它只是没有显示
标签: jquery ruby-on-rails image iteration