2011-04-18 115 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