【问题标题】:rails way to mouseover or hover and then mouseout back to post.imagerails 方式鼠标悬停或悬停,然后 mouseout 回到 post.image
【发布时间】:2017-02-28 08:30:04
【问题描述】:

我无法弄清楚循环我的@posts的rails方式是什么,并且我的link_to曾经有一个绿色背景颜色的鼠标悬停或悬停带有一个很棒的字体图标,然后在mouseout让它去回到我的post.image

*在鼠标悬停时-背景变成绿色,带有字体真棒图标

*on mouseout - 恢复正常并显示 post.image

<!-- Portfolio Grid Section -->
        <section id="portfolio">
            <div class="container">
                <div class="row">
                    <div class="col-lg-12 text-center">
                        <h2>Portfolio</h2>
                        <hr class="star-primary">
                    </div>
                </div>
                <div class="row col-md-8 col-md-offset-2">
                    <% @posts.each do |post| %> 
                        <div class="col-sm-4 portfolio-item">
                            <%= link_to image_tag( post.image, class: "img-circle", size: "200x200"), post_path(post)  %>
                        </div>
                    <% end %>
                </div>
            </div>
        </section>

【问题讨论】:

  • 只使用css hover
  • github github.com/Mnapper3/portfolio 我想要的悬停背景显示在活动管理员中创建的 img 后面,并且它们保存在 s3 上,我希望有人可以克隆 repo 并成为哦“你这个白痴”你没有不要这样做。

标签: javascript jquery css ruby-on-rails


【解决方案1】:

根据您进一步的 cmets,我猜您希望在图像顶部叠加,而不是在悬停时替换图像。

为此,请在图像下方和链接内创建一个绝对定位的 span/div。将跨度不透明度设置为 0,然后在链接悬停时将其设置为 1。诀窍是使用 CSS 过渡属性,通过在 0.5 秒内更改不透明度和背景颜色,使其看起来像平滑过渡。

我没有测试下面的代码让你走上正轨。

导轨/HTML:

<div class="col-sm-4">
  <%= link_to post_path(post), class: "post-item" do %>
    <%= image_tag( post.image, class: "img-fluid") %>
    <span class="overlay"><i class="fa fa-check"></i></span>
  <% end %>
</div>

CSS

.post-item{
  display:block;
  position:relative;
}
.post-item span{
  overlay: 0;
  position:absolute;
  display:block;
  transition: all 0.5s ease;
  background-color: transparent;
}
.post-item:hover span{
  opacity: 1;
  background-color: green;
}

【讨论】:

  • 图片确实隐藏了很棒的字体,但是绿色背景没有显示出来,当我悬停时它会进出故障,我不明白为什么我把 img-circle:hover doesn' t 改变背景颜色:绿色;并将 z-index 设置为 3 将不起作用(我假设图片不会在悬停时消失吗?)
  • 背景图片不能设置背景颜色,因此 img-circle:hover 无效。
猜你喜欢
  • 2015-09-03
  • 2014-02-22
  • 1970-01-01
  • 2011-08-04
  • 2018-09-03
  • 2015-04-22
  • 2011-05-26
  • 2017-10-14
  • 1970-01-01
相关资源
最近更新 更多