jQuery如何使图像在加载时淡入淡出? [英] jQuery How do you get an image to fade in on load?
问题描述
我要做的就是在加载页面时淡入我的徽标.我是jQuery的新手,在加载时无法淡入淡出,请提供帮助.抱歉,如果这个问题已经回答了,我看了一下,尝试为其他问题改编其他答案,但是似乎没有任何效果,这开始使我感到沮丧.
All I want to do is fade my logo in on the page loading. I am new today to jQuery and I can't managed to fadeIn on load please help. Sorry if this question has already been answered I have had a look and try to adapt other answers for different question but nothing seems to work and its starting to frustrate me.
谢谢.
代码:
<script type="text/javascript">
$(function () {
.load(function () {
// set the image hidden by default
$('#logo').hide();.fadeIn(3000);
}}
</script>
<link rel="stylesheet" href="challenge.css"/>
<title>Acme Widgets</title>
</head>
<body>
<div id="wrapper">
<div id="header">
<img id="logo" src="logo-smaller.jpg" />
</div>
<div id="nav">
navigation
</div>
<div id="leftCol">
left col
</div>
<div id="rightCol">
<div id="header2">
header 2
</div>
<div id="centreCol">
body text
</div>
<div id="rightCol2">
right col
</div>
</div>
<div id="footer">
footer
</div>
</div>
</body>
</html>
推荐答案
我想出了答案!您需要使用window.onload函数,如下所示.感谢Tec guy和Karim的帮助.注意:您仍然还需要使用文档准备功能.
I figure out the answer! You need to use the window.onload function as shown below. Thanks to Tec guy and Karim for the help. Note: You still need to use the document ready function too.
window.onload = function() {$('#logo').hide().fadeIn(3000);};
$(function() {$("#div").load(function() {$('#div').hide().fadeIn(750););
将它放在图片后也对我有用...谢谢
It also worked for me when placed right after the image...Thanks
这篇关于jQuery如何使图像在加载时淡入淡出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!