admin管理员组文章数量:1289540
Hey everyone. This seems easy enough, but for some reason I'm having a hard time piecing it together. I want to create an animated "fade in" effect, where a div fades from 0 opacity to 50% opacity, and stops.
As far as I understand:
var duration = 1000;
$('#mydiv').fadeIn(duration);
will fade the div to 100%, with no option of limiting this.
Is there an elegant way of setting the finishing opacity?
Hey everyone. This seems easy enough, but for some reason I'm having a hard time piecing it together. I want to create an animated "fade in" effect, where a div fades from 0 opacity to 50% opacity, and stops.
As far as I understand:
var duration = 1000;
$('#mydiv').fadeIn(duration);
will fade the div to 100%, with no option of limiting this.
Is there an elegant way of setting the finishing opacity?
Share Improve this question edited Jan 18, 2011 at 1:08 Zaven Nahapetyan asked Jan 17, 2011 at 20:35 Zaven NahapetyanZaven Nahapetyan 1,2791 gold badge11 silver badges15 bronze badges 2- 2 I hate it when it requires a long explanation like that.... then all the answers are 1-liners – Ben Commented Jan 17, 2011 at 20:42
- The cruel irony is that the more you learn the better your questions get. If he played with the jQuery source code more he'd probably have a shorter question. If he knew about jsfiddle he'd probably have a working example for us of the issue, etc, etc... – Incognito Commented Jan 17, 2011 at 20:49
4 Answers
Reset to default 8I think you use the fadeTo() method.
.fadeTo();
That's it.
http://api.jquery./fadeTo/
You will notice issues with IE and alpha channels.
These are lovely for FF, chrome and the rest...
opacity:0;
-moz-opacity:0;
IE expects to see this:
filter:alpha(opacity=x).
use .fadeTo() with the second parameter set to 0.5.
No need to add the different browser conditional - jQuery will handle opacity in IE and firefox just by using the standard opacity call:
$('#mydiv').animate(
{
opacity : 0.5
}, 500
);
And yeah, use fadeTo like the others mentioned.
本文标签: javascriptHow do you fade in *partially* in jQueryStack Overflow
版权声明:本文标题:javascript - How do you fade in *partially* in jQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741440517a2378888.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论