我有以下悬停效果,我现在如何淡入和淡出?
HTML
<article>
hello world
</article>
CSS
article
{
position: relative;
float: left;
margin: 0 16px 16px 0;
padding: 10px;
width: 228px;
height: 228px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
overflow: hidden;
background: green;
}
article:hover:after
{
content: '';
position: absolute;
top: 0;
left: 0;
width: 322px;
height: 322px;
background: #fff;
-webkit-transform: translate(-161px, -161px) rotate(135deg);
-moz-transform: translate(-161px, -161px) rotate(135deg);
transform: matrix(-161px, -161px) rotate(135deg);
opacity: 0.5;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
答案 0 :(得分:5)
如果您没有起点和终点,您的元素将不会变换或移动。您要做的是首先设置article:after
,然后设置当您将鼠标悬停在文章上时应该是什么。这样的事情:http://jsfiddle.net/E8dNe/1/
article:after {
content: '×';
position: absolute;
top: 0;
left: 0;
width: 322px;
height: 322px;
background: #fff;
opacity: 0;
-webkit-transition: 1s all ease-in-out;
}
article:hover:after {
-webkit-transform: translate(-161px, -161px) rotate(135deg);
opacity: .5;
}