[英]CSS Transition not working properly
I have the following code: http://jsfiddle.net/8TG8L/ 我有以下代码: http : //jsfiddle.net/8TG8L/
On another part of my HTML I can get the transition CSS to work great, but here on the right hand side I cannot get the transition to have any delay. 在我的HTML的另一部分,我可以使过渡CSS很好地工作,但是在右侧,我无法使过渡具有任何延迟。
Relevant code: 相关代码:
.home_subvid_hover {
background-image:url('http://www.ptroa.com/images/video_hover.png');
/*background-repeat:no-repeat;*/
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
-o-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
}
EDIT : 编辑 :
To clarify, please look at this code: http://jsfiddle.net/9UuY7/ 为了澄清,请查看以下代码: http : //jsfiddle.net/9UuY7/
That one works although it's the same principle as the first one, why is that? 尽管与第一个原理相同,但该原理仍然有效,为什么呢? Thanks, 谢谢,
The reason the background isn't animated, is because the backround-image
isn't set on the initial class .home_subvid
. 背景未设置动画的原因是,未在初始类.home_subvid
上设置.home_subvid
backround-image
。
You can't animate background-image:none
to background-image:url(...)
. 您无法将background-image:none
为background-image:url(...)
动画。
If you try this, it's gonna work: 如果您尝试此操作,它将起作用:
.home_subvid {
background-image:url('http://placehold.it/1x1/000');
background-size: cover;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
-o-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
}
.home_subvid:hover {
background-image:url('http://www.ptroa.com/images/video_hover.png');
/*background-repeat:no-repeat;*/
}
你的CSS正在改变从一无所有的背景图像的图像 ,它在当前一代的CSS不能动画。
You can't transition background images from none
to an image, see this document on MDN . 您无法将背景图像none
图像过渡到图像, 请参阅MDN上的此文档 。 Transitioning from image to image doesn't have amazing browser support either; 从图像过渡到图像也没有令人赞叹的浏览器支持。 as far as I know it's only supported in Chrome. 据我所知,Chrome仅支持该功能。
You can, however, create a similar effect with different markup/CSS. 但是,您可以使用不同的标记/ CSS创建类似的效果。
How about an element made invisible with opacity: 0;
如何使元素变得opacity: 0;
and then transitioned into opacity: 1;
然后转变为opacity: 1;
when hovered? 何时悬停?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.