[英]FadeIn/out effect on hover
I have a FadeIn/Out effect on my page for a couple of Social logos. 我的页面上有一些FadeIn / Out效果,可以显示几个社交徽标。
It seems they work fine but the initial fade in wont work untill i hover over them. 它似乎工作正常,但最初的淡入淡出不会工作,直到我将它们悬停在它们上面。
How can i make the fade in function work when the page is loaded? 如何在加载页面时使淡入淡出功能?
<script type='text/javascript'>
$(document).ready(function()
{
$("img.a").hover(function()
{
$(this).stop().animate({"opacity": "1"}, "fast");
},
function()
{
$(this).stop().animate({"opacity": "0.5"}, "fast");
});
});
</script>
The Page: 这页纸:
www.tranceil.fm
www.tranceil.fm
I know you need a jQuery solution but why to use it if you can do it with CSS? 我知道你需要一个jQuery解决方案,但是为什么要使用它,如果你能用CSS做到这一点?
img.class {
opacity: .5;
transition: opacity 2s;
/* Transitions will take care of the smooth effect */
-moz-transition: opacity 2s; /* Firefox 4 */
-webkit-transition: opacity 2s; /* Safari and Chrome */
-o-transition: opacity 2s; /* Opera */
}
img.class:hover {
opacity: 1;
}
Note: Am not using rgba
because it is just an image 注意:我没有使用
rgba
因为它只是一个图像
For IE support you can use CSS3 Pie 对于IE支持,您可以使用CSS3 Pie
If you still want to stick to jQuery, am not that good with it but I guess you can set initial opacity for your social icon by simply defining it in your CSS 如果你仍然想坚持jQuery,我不是很好,但我猜你可以通过简单地在你的CSS中定义它来为你的社交图标设置初始不透明度
img.a {
opacity: .5;
}
Simply set the CSS already once the document is loaded. 只需在加载文档后设置CSS即可。
$(document).ready(function(){
$("img.a").css({"opacity": "0.5"});
$("img.a").hover(
function() {
$(this).stop().animate({"opacity": "1"}, "fast");
},
function() {
$(this).stop().animate({"opacity": "0.5"}, "fast");
}
);
});
How about 怎么样
<script type='text/javascript'>
$(document).ready(function(){
$("img.a").hover(
function() {
$(this).stop().animate({"opacity": "1"}, "fast");
},
function() {
$(this).stop().animate({"opacity": "0.5"}, "fast");
}
).css('opacity':'0.5');
});
</script>
You can do it with CSS too but jQuery is a little more browser-safe. 您也可以使用CSS,但jQuery更安全。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.