【问题标题】:Animating Hover effect not working inside of ul > li动画悬停效果在 ul > li 内部不起作用
【发布时间】:2013-02-13 21:00:29
【问题描述】:

所以当您滚动左侧的大型销售图片时,我正尝试重新创建这个 cool hover effect seen here

Chris Coyier 然后创建了一个super detailed tutorial here. 基本上在翻转时,这个很酷的对角线剥离背景开始在你的 div/box/image 后面动画。

除了我将 div 包含在列表 (ul li) 中之外,一切正常。一旦我这样做了,我的代码就会停止工作:(有没有办法解决这个问题?或者我犯了什么新手错误?

这是我的代码笔: http://codepen.io/leongaban/pen/hpzqD

HTML

<ul>
  <li>

    <div class="thumb">
      <div class="thumb-hover"></div>
        <a href="#">
            <img src="http://f.cl.ly/items/3k3d1g3K34470d2v2K3O/50d942d85384a.jpeg"/>
        </a>
    </div>

  </li>
</ul>

CSS

ul li {
list-style: none;
float: left;
}

.thumb {
  width: 376px;
  padding: 15px;
  position: relative;
  float: left;
  margin: 0 20px 0 0;
}
.thumb > img {
  display: block;
  position: relative;
}
.thumb:hover .product-hover, .thumb:active .product-hover {
  opacity: 1;
}

.thumb-hover {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
  background-size: 30px 30px;
  background-image: linear-gradient(45deg, rgba(0, 0, 0, 0.1) 25%, transparent 25%,   transparent 50%, rgba(0, 0, 0, 0.1) 50%, rgba(0, 0, 0, 0.1) 75%, transparent 75%, transparent);
  animation: barberpole 0.5s linear infinite;
}

@keyframes barberpole {
  from {
    background-position: 0 0;
  }

  to {
    background-position: 60px 30px;
  }
}

【问题讨论】:

  • 编辑我开始让我的 codepen fork 与 ul 一起工作 > li codepen.io/leongaban/pen/nbCpw 现在必须弄清楚我的主要项目中发生了什么

标签: html css animation hover


【解决方案1】:

您的示例中似乎有一个小错字。 .product-hover 应该变成 .thumb-hover

另外,你会希望你的 css 是 .thumb > a{ display: block;位置:相对; } 否则,条形动画将位于您的图像之上。

在您的 codepen 中将 scss 更改为以下内容:

> a {
 display: block;
 position: relative;
}
&:hover, &:active {
 .thumb-hover {
   opacity: 1; 
 }

}

http://codepen.io/anon/pen/ACewa

【讨论】:

【解决方案2】:

假设您试图影响代码 sn-p 中的 &lt;img&gt;,这将不起作用:

.thumb > img { ... }

那(特别是&gt;)意味着“将以下规则应用于&lt;img&gt; 元素,这些元素是.thumb 类的任何元素的直接后代(子)。” 但根据您的标记,事实并非如此。尝试删除该 CSS 规则定义中的 &gt;

【讨论】:

猜你喜欢
  • 2013-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-10
  • 2017-08-26
  • 1970-01-01
相关资源
最近更新 更多