CSS3 淡入淡出效果
a {
float: left;
width: 32px;
height: 32px;
text-align: left;
text-indent:-9999px;
background: url('../img/button.png') no-repeat 0 0;
-webkit-transition: background 300ms ease-in 2s; /* property duration timing-function delay */
-moz-transition: background 300ms ease-in 2s;
-o-transition: background 300ms ease-in 2s;
transition: background 300ms ease-in 2s;
-webkit-transition-property: background;
-webkit-transition-duration: 300ms;
-webkit-transition-timing-function: ease-in;
-webkit-transition-delay: 100ms;
-moz-transition-property: background;
-moz-transition-duration: 300ms;
-moz-transition-timing-function: ease-in;
-moz-transition-delay: 100ms;
-o-transition-property: background;
-o-transition-duration: 300ms;
-o-transition-timing-function: ease-in;
-o-transition-delay: 100ms;
transition-property: background;
transition-duration: 300ms;
transition-timing-function: ease-in;
transition-delay: 100ms;
}
a:hover {
background:position: 0 -32px;
}
..目前它具有向上/向下滚动效果,但我希望背景随淡入淡出效果而变化,我应该在CSS中更改什么?
谢谢!
a {
float: left;
width: 32px;
height: 32px;
text-align: left;
text-indent:-9999px;
background: url('../img/button.png') no-repeat 0 0;
-webkit-transition: background 300ms ease-in 2s; /* property duration timing-function delay */
-moz-transition: background 300ms ease-in 2s;
-o-transition: background 300ms ease-in 2s;
transition: background 300ms ease-in 2s;
-webkit-transition-property: background;
-webkit-transition-duration: 300ms;
-webkit-transition-timing-function: ease-in;
-webkit-transition-delay: 100ms;
-moz-transition-property: background;
-moz-transition-duration: 300ms;
-moz-transition-timing-function: ease-in;
-moz-transition-delay: 100ms;
-o-transition-property: background;
-o-transition-duration: 300ms;
-o-transition-timing-function: ease-in;
-o-transition-delay: 100ms;
transition-property: background;
transition-duration: 300ms;
transition-timing-function: ease-in;
transition-delay: 100ms;
}
a:hover {
background:position: 0 -32px;
}
.. currently it has scroll up/down effect, but I want the background to change with fade effect, what should I change in the CSS?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法在两个背景图像之间进行转换,因为浏览器无法知道您想要插入什么。正如您所发现的,您可以转换背景位置。如果您希望图像在鼠标悬停时淡入,我认为使用 CSS 过渡的最佳方法是将图像放在包含元素上,然后将链接本身的背景颜色设置为透明:
You can't transition between two background images, as there's no way for the browser to know what you want to interpolate. As you've discovered, you can transition the background position. If you want the image to fade in on mouse over, I think the best way to do it with CSS transitions is to put the image on a containing element and then animate the background colour to transparent on the link itself:
滚动效果是通过在 css 中指定通用“背景”属性而不是更具体的背景图像引起的。通过设置背景属性,动画将在所有属性之间过渡..背景颜色,背景图像,背景位置..等从而引起滚动效果..
例如
The scrolling effect is cause by specifying the generic 'background' property in your css instead of the more specific background-image. By setting the background property, the animation will transition between all properties.. Background-Color, Background-Image, Background-Position.. Etc Thus causing the scrolling effect..
E.g.
可以使用以下结构:
等等...
其中
包含
锚标记,其中包含如上所示的跨度。然后插入以下 css:
position:relative;
标记一个
height
,width
宽度
&height
为 100%,以便和
具有相同的尺寸
< /code> 和
获取
position:relative;
。标记将具有“OFF”
background-position
和将具有“ON”
背景位置
。使用不透明度 0 对于
:hover
状态,使用不透明度 1
元素上的
-webkit
或-moz
过渡您将能够使用过渡效果,同时仍默认为旧的
背景位置
交换。不要忘记插入 IE alpha 过滤器。It's possible, use the structure below:
etc...
Where the
<li>
contains an<a>
anchor tag that contains a span as shown above. Then insert the following css:position: relative;
<a>
tag aheight
,width
<span>
width
&height
to 100%, so that both<a>
and<span>
have same dimensions<a>
and<span>
getposition: relative;
.<a>
tag will have the 'OFF'background-position
, and the<span>
will have the 'ON'background-poisiton
.<span>
:hover
state use opacity 1 for<span>
-webkit
or-moz
transition on the<span>
elementYou'll have the ability to use the transition effect while still defaulting to the old
background-position
swap. Don't forget to insert IE alpha filter.