fadeIn 使用 $(document).ready( ) 导致明显的滞后
我对 javascript 比较陌生,正在构建一个网页。我使用 Pikachoose 幻灯片作为页面上的横幅,但我找不到让它在加载时淡入的方法。当页面加载时,幻灯片的第一张图像会直接加载,而不是淡入。
我决定在整个幻灯片上使用 fadeIn javascript 函数。这是我的 javascript:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.pikachoose.js"></script>
<script language="javascript">
$(document).ready(function (){
$('#slideshow').hide().fadeIn(1500);
$("#pikame").PikaChoose();
});
</script>
所以基本上它会淡入,然后 Pikachoose 启动。但是当页面加载时,淡入淡出有明显的滞后。它有效,但有点不稳定。一旦加载,幻灯片就可以正常工作了。有没有办法稍微延迟淡入,直到整个页面加载,这样它就不会被束缚?我认为这就是就绪函数所完成的任务。
您认为为什么会发生这种情况?有什么想法吗?谢谢。
编辑
这是完整的代码:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.pikachoose.js"></script>
<script language="javascript">
$(document).ready(function (){
$('#slideshow').hide().fadeIn(1500);
$("#pikame").PikaChoose();
});
</script>
<script type="text/javascript" src="js/jquery.pikachoose.js"></script>
<div id="slideshow">
<ul id="pikame" >
<li><a href="http://www.pikachoose.com"><img src="slideshow/purplebackground.png"/></a></li>
<li><a href="http://www.pikachoose.com"><img src="slideshow/redbackground.png"/></a></li>
<li><a href="http://www.pikachoose.com"><img src="slideshow/yellowbackground.png"/></a></li>
</ul>
</div>
I'm relatively new to javascript and am building a web page. I'm using the Pikachoose slideshow as a banner on the page and I couldn't find a way to get it to fade in on load. When the page loads, the first image of the slideshow just loads straight up instead of fading in.
I decided to just use a fadeIn javascript function on the whole slideshow. Here is my javascript:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.pikachoose.js"></script>
<script language="javascript">
$(document).ready(function (){
$('#slideshow').hide().fadeIn(1500);
$("#pikame").PikaChoose();
});
</script>
So basically it fades in and then Pikachoose starts up. BUT there is a noticeable lag on the fadein when the page loads. It works but it's a little choppy. Once it loads the slideshow works without any problems. Is there a way to delay the fadeIn slightly until the whole page loads so it's not getting tied up? I thought that was what the ready function accomplished though.
Why do you think that's happening? Any ideas? Thanks.
EDIT
Here's the full code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.pikachoose.js"></script>
<script language="javascript">
$(document).ready(function (){
$('#slideshow').hide().fadeIn(1500);
$("#pikame").PikaChoose();
});
</script>
<script type="text/javascript" src="js/jquery.pikachoose.js"></script>
<div id="slideshow">
<ul id="pikame" >
<li><a href="http://www.pikachoose.com"><img src="slideshow/purplebackground.png"/></a></li>
<li><a href="http://www.pikachoose.com"><img src="slideshow/redbackground.png"/></a></li>
<li><a href="http://www.pikachoose.com"><img src="slideshow/yellowbackground.png"/></a></li>
</ul>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$.ready 将在 DOM 准备好时触发,而不是在页面加载时触发。
在页面加载之前,使用动画时您可能会得到不想要的结果,因为您想要设置动画的元素的宽度/高度等属性可能仍然未知。此外,pikachoose 使用的图像可能仍未完全加载。
所以你最好使用 $(window).load() 来执行你的函数。
要在页面加载之前隐藏幻灯片,您可以使用以下命令:
$.ready will fire when the DOM is ready, not when the page is loaded.
Before the page is loaded you may get undesired results when using animations because properties like width/height of the elements you like to animate may still be unknown. Also the images used by pikachoose may still not be loaded completely.
So you better use $(window).load() instead to execute your functions.
To have the slideshow hidden before the page is loaded, you may use this: