通过幻灯片动画过渡背景色 [英] Transition background-color via slide animation

查看:53
本文介绍了通过幻灯片动画过渡背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用CSS过渡来更改悬停元素的背景颜色.我想通过使其从底部向上滚动来做到这一点.我可以使用此功能淡化背景,但是我希望它向上滑动:

I am trying to change the background-color of an element on hover by using CSS transitions. I want to do this by having it scroll up from the bottom. I can fade the background in using this, but I would like it to slide up:

-webkit-transition: background-color 0.5s linear;
-moz-transition: background-color 0.5s linear;
-o-transition: background-color 0.5s linear;  
transition: background-color 0.5s linear;

另一个想法是,向上滚动一个单独的元素并应用背景会更好吗?

One other thought, would it be better to scroll up a separate element with the background applied to it?

推荐答案

滑动背景颜色,您需要逐步使用背景图像或某种渐变调整背景位置:

In order to slide the background color up you would need to use a background image, or a gradient of some sort, while gradually adjusting the background-position:

.box {
    width: 200px; height: 100px;
    background-size: 100% 200%;
    background-image: linear-gradient(to bottom, red 50%, black 50%);
    -webkit-transition: background-position 1s;
    -moz-transition: background-position 1s;
    transition: background-position 1s;
}

.box:hover {
    background-position: 0 -100%;
}

<div class="box"></div>

这篇关于通过幻灯片动画过渡背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆