我有一个使用:: after伪填充背景的按钮。目前它从左到右填充,这有意义,因为宽度从0到100%。但是,我希望它能够改变它的填充方式。
a.project--link {
margin: 2rem auto 0 auto;
padding: 1rem 0;
display: block;
border: 1px solid black;
box-shadow: 0 0 10px rgba(red, .2);
width: 100%;
transition: all .2s ease;
z-index: 1;
}
a.project--link:hover {
box-shadow: 0 0 10px rgba(red, .7);
transform: scale(1.02);
transition: all .2s ease;
}
a.project--link::after {
display: block;
content: '';
height: 100%;
width: 0;
top: 0;
z-index: -1;
background-color: red;
position: absolute;
}
a.project--link:hover::after {
width: 100%;
transition: .3s linear;
}

<a href="#" class="project--link">View Project</a>
&#13;
如果有人能够阐明如何翻动动画,那将是一个巨大的帮助。
答案 0 :(得分:0)
使用transform: scaleX()
代替width
并使用transform-origin
来控制方向。
a.project--link {
margin: 2rem auto 0 auto;
padding: 1rem 0;
display: block;
border: 1px solid black;
box-shadow: 0 0 10px rgba(red, .2);
width: 100%;
transition: all .2s ease;
z-index: 1;
position: relative;
}
a.project--link:hover {
box-shadow: 0 0 10px rgba(red, .7);
transform: scale(1.02);
transition: all .2s ease;
transform-origin: 0 100%;
}
a.project--link::after {
display: block;
content: '';
height: 100%;
top: 0;
width: 100%;
z-index: -1;
background-color: red;
position: absolute;
transition: .3s linear;
transform: scaleX(0);
transform-origin: 100% 0;
}
a.project--link:hover::after {
transform: scaleX(1);
}
<a href="#" class="project--link">View Project</a>