admin管理员组文章数量:1279234
I want my page to open with a picture and I want that picture to fade-out 10 seconds after. Which way is the best way I can do it ? Is there any way I can do it with Css3 ?
I want my page to open with a picture and I want that picture to fade-out 10 seconds after. Which way is the best way I can do it ? Is there any way I can do it with Css3 ?
Share Improve this question edited Dec 14, 2011 at 23:11 Merlyn Morgan-Graham 59.2k16 gold badges131 silver badges187 bronze badges asked Dec 14, 2011 at 23:06 ExtelliqentExtelliqent 1,8566 gold badges35 silver badges53 bronze badges 1- What's the mark-up for the page? And what've you tried? – David Thomas Commented Dec 14, 2011 at 23:07
4 Answers
Reset to default 7So long as you've given the element to fade out an id
(or have some way to reference it from JavaScript):
window.setTimeout(
function(){
$('#pictureID').fadeOut('slow');
},10000);
JS Fiddle demo.
I'm assuming that you're using the image as a splash screen, of sorts? If so, then you can use position: absolute
to position that image over the content of the page, and then fade out to reveal the contents below (JS Fiddle demo).
If, however, you also want the user to be able to hover
over the image to hold it in place then the following could be used (the above, but with a couple of amendments):
var fadeAnim = window.setTimeout(
function(){
$('#i').fadeOut('slow');
},10000);
$('#i').hover(
function(){
window.clearTimeout(fadeAnim);
},
function(){
$(this).fadeOut(500);
});
JS Fiddle demo.
References:
- JavaScript (from the Mozilla Developer Network's JavaScript resource):
window.setTimeout()
.window.clearTimeout()
.
- jQuery (from the jQuery API):
fadeOut()
.
setTimeout(function() {
$('.imgClass').fadeOut('slow')
}, 10000);
You will have to use Javascript to do that. You can cross Javascript (our jQuery) with CSS3 but for cross-browser issue you'd better do it in full jquery. To do so, you can use load(), delay() and fadeOut().
Try :
$('#yourImg').ready(function(){
$(this).delay(10000).fadeOut();
});
You can use setTimeout()
to delay the start of the fade, and then you can fade it out using either jquery(or another javascript library such as mootools) or you can add a class to the element and have it transition using a css3 transition. Since the jQuery version has already been posted, i'll post the css3 version. http://jsfiddle/Tentonaxe/3Vnt7/
CSS:
#demo {
transition: opacity 2s ease-in;
-moz-transition:opacity 2s ease-in;
-o-transition: opacity 2s ease-in;
-webkit-transition: opacity 2s ease-in;
border: 4px solid green;
background-color: #ededed;
width: 75px;
height: 75px;
}
.hidden {
opacity: 0.0;
}
HTML:
<div id="demo"></div>
Javascript:
setTimeout(function(){
document.getElementById('demo').className = "hidden";
},10000);
本文标签: javascriptFading image after specific amount of timeStack Overflow
版权声明:本文标题:javascript - Fading image after specific amount of time - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741299997a2371039.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论