如何在 Jquery 中准备好内容后才使其淡出?
我看过 load()
和 ready()
的示例,但它们似乎总是适用于窗口或文档正文,或者 div 或 img 或类似的东西。
我有一个 hover()
函数,当您将鼠标悬停在它上面时,它会使用 fadeIn()
来显示它。问题是,div 内的图像尚未加载,所以它最终只是出现。我需要的代码只允许图像在其内容完全加载时褪色。当我插入如下所示的其他选择器时,它不起作用
$(this).next(".menuPopup").ready(function () { //or load(), neither work
fadeTo(300, 1);
});
编辑:相关代码
$( '.leftMenuProductButton' ).hover (
function () {
$(this).next(".menuPopup").stop().css("opacity", 1).fadeIn('slow');
},
function () {
$(this).next(".menuPopup").stop().hide();
});
HTML
<div class="leftMenuProductButton"> Product 1</div>
<div id="raceramps56" class="menuPopup"><IMG SRC="myimage.jpeg"> </div>
I've seen examples for load()
and ready()
, but they always seem to apply to the window or document body, or a div or img or something like that.
I have a hover()
function, and when you hover over it, it uses fadeIn()
to reveal it. Problem is, the images inside the div aren't loaded yet, so it ends up just appearing anyway. I need code that will only allow the image to fade when it's contents are fully loaded. When I just plug in other selectors like the following, it doesn't work
$(this).next(".menuPopup").ready(function () { //or load(), neither work
fadeTo(300, 1);
});
EDIT: Relevant code
$( '.leftMenuProductButton' ).hover (
function () {
$(this).next(".menuPopup").stop().css("opacity", 1).fadeIn('slow');
},
function () {
$(this).next(".menuPopup").stop().hide();
});
HTML
<div class="leftMenuProductButton"> Product 1</div>
<div id="raceramps56" class="menuPopup"><IMG SRC="myimage.jpeg"> </div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能应该链接动画:
我以前做过类似的事情,而且效果很好。我认为很多灯箱都这样做。
You should probably go with chaining the animations:
I've done something like this before, and it worked pretty well. I think a lot of Lightboxes do this.
该功能
可能就是您正在寻找的功能。
请参阅: SO 帖子
The function
is probably what you're looking for.
See: SO post
您可以使用 window.onLoad,它在加载所有内容之前不会触发。
You could use window.onLoad, that doesn't fire until everything is loaded.