我已经开始为我正在开发的 Rails 应用程序创建翻转图像效果。我正在使用 twitter-bootstrap-rails gem 来保持应用程序在设备上看起来不错。我当前的实现遇到的问题是,当调整浏览器大小时,图像不再调整为浏览器的宽度,并且翻转效果超出了图像的边界。我认为问题源于.photo
课堂,但我不确定如何解决它,或者是否有更好的方法来实现我想要的结果?
HTML
<% @photos.each do |photo| %>
<div class="photo row">
<div class="span8 photo"><%= image_tag photo.image_url(:large).to_s %></div>
<div class="span4 hover">
<div class="bg"></div>
<div class="description">
<h4><%= link_to photo.title, photo_path(photo) %></h4>
<hr>
<p><%= raw photo.tag_list.map { |t| link_to t, tag_path(t)}.join(' ') %></p>
</div>
</div>
</div>
<% end %>
CSS:
.photo {
position: relative;
width: 770px;
}
.photo .hover {
position: absolute;;
height: 90.4%;
left: 3.09%;
top: 4.8%;
width: 93.82%;
display: none;
}
.photo .hover .bg {
z-index: 1;
position: absolute;
height: 100%;
width: 100%;
background: #FFF;
-webkit-opacity: 0.8;
-moz-opacity: 0.8;
filter:alpha(opacity=80);
opacity: 0.8;
}
.photo .hover .description {
position: relative;
text-align: center;
top: 40%;
z-index: 2;
}
JS
jQuery(document).ready(function($) {
$(".photo").mouseenter(function () {
$(this).find('.hover').fadeIn(300);
}).mouseleave(function (){
$(this).find('.hover').stop(true, true).fadeOut(300);
});
}); /* End Dom Ready */