2011-04-18 109 views
0

如何使用CSS或jQuery来动画元素的“不透明度”?元素的动画不透明度

+1

我认为你需要澄清你的问题。你在谈论jQuery'.fadeOut()'/'.fadeIn()'? – Tejs 2011-04-18 21:05:43

+0

可能与CSS3 – ajcw 2011-04-18 21:07:13

+1

真棒downvote,做得好!如果OP甚至没有足够的意义来成为英语为母语的人,那么,他*应该*由于静戈而被降级!我特别喜欢你,没有评论就低估了你;就是那种精神! – 2011-04-18 21:14:42

回答

0

号您需要使用.fadeIn('slow or fast').fadeOut('slow or fast')

+0

这些并不是用于在jQuery动画中指定速度的唯一两个选项。 – Shaz 2015-04-14 21:20:35

1

CSS3过渡可以做到这一点。我做了一个鼠标激活工具栏下面:

CSS

<style type="text/css"> 
#cmsToolBar { 
    font-family: helvetica,arial,sans-serif; 
    font-size: 1.1em; 
    padding: 5px; 
    line-height: 1.5; 
    min-height: 1em; 
    width: 100%; 
    position: fixed; 
    top: 0; 
    left: 0; 
    color: black; 
    background-color: #DDDDBB; 
    opacity: 0.15; 
    border-bottom: dotted 1px black; 
    transition-duration: .2s; 
    -moz-transition-duration: .2s; 
    -webkit-transition-duration: .2s; 
    -o-transition-duration: .2s; 
} 
#cmsToolBar:hover { 
    min-height: 5em; 
    opacity: .98; 
} 
</style> 

HTML

<div id="cmsToolBar"> 
    <p>This is where the CMS tool bar will go</p> 
</div> 
+0

记住IE10pp2的-ms-transition ...另外我会添加没有供应商前缀的转换,以便将来兼容。 – 2011-04-18 21:13:48

+0

不知道IE版本。但是上面的例子已经定义了一个通用的转换。 – GordonM 2011-04-18 21:18:56

2

当然,使用CSS转换:

div { 
 
    opacity: 1; 
 
    -moz-transition: all 0.3s ease-out; /* FF4+ */ 
 
    -o-transition: all 0.3s ease-out;  /* Opera 10.5+ */ 
 
    -webkit-transition: all 0.3s ease-out; /* Safari 3.2+, Chrome */ 
 
    -ms-transition: all 0.3s ease-out;  /* IE10+ */ 
 
    transition: all 0.3s ease-out;   /* standard format */ 
 
} 
 

 
div:hover { 
 
    opacity: 0.3;  
 
}
<div>Hover over me with your mouse!</div> 
 
<div>Hover over me with your mouse!</div> 
 
<div>Hover over me with your mouse!</div> 
 
<div>Hover over me with your mouse!</div> 
 
<div>Hover over me with your mouse!</div> 
 
<div>Hover over me with your mouse!</div>

+0

为什么这不是公认的答案?感谢您分享我需要的信息 – Awena 2015-04-10 13:38:07

+1

@Awena感谢您提醒我这篇文章。我还将该示例包含在代码片段中,而不是依赖于第三方。 – Shaz 2015-04-14 21:19:07