admin管理员组文章数量:1302274
I have a following situation: I want to show my images at once only when the page is fully loaded because I want to avoid showing images one by one inside document ready function (they are initially hidden and want to show them at once only when document is finished loading), so I am using$(window).load(function () {});
When I use this function it runs fine and behaves as expected, but my only problem is that load function is deprecated.
For example if I use the code below without $(window).load
i can see my images loaded one by one which is not an option (setTimeout is no option either).
My question: How can I achieve the same behavior without using $(window).load
? Thank you!!
Sample code:
$(document).ready(function(){
//on document ready HIDE my images
glowHide.hide();
//on page LOAD show all images AT ONCE (works fine but depreciated)
$(window).load(function(){
glowHide.show();
});
});
I have a following situation: I want to show my images at once only when the page is fully loaded because I want to avoid showing images one by one inside document ready function (they are initially hidden and want to show them at once only when document is finished loading), so I am using$(window).load(function () {});
When I use this function it runs fine and behaves as expected, but my only problem is that load function is deprecated.
For example if I use the code below without $(window).load
i can see my images loaded one by one which is not an option (setTimeout is no option either).
My question: How can I achieve the same behavior without using $(window).load
? Thank you!!
Sample code:
$(document).ready(function(){
//on document ready HIDE my images
glowHide.hide();
//on page LOAD show all images AT ONCE (works fine but depreciated)
$(window).load(function(){
glowHide.show();
});
});
Share
Improve this question
edited Oct 5, 2012 at 12:57
Dejo Dekic
asked Oct 5, 2012 at 12:46
Dejo DekicDejo Dekic
2,1264 gold badges29 silver badges51 bronze badges
11
- So you want to show all images at once, only when all the images have been loaded fully? – Tim B James Commented Oct 5, 2012 at 12:49
- Not something you should worry about. Serve up valid HTML and let the browser decide how best to load its images. – user229044 ♦ Commented Oct 5, 2012 at 12:49
- Yes that is what i want to do! My code is working good but load is depreciated:( – Dejo Dekic Commented Oct 5, 2012 at 12:49
-
3
Can you do
$(window).on("load", function(){...})
? I've not tried it, buton
would bind the load event to the window. Figured it may be worth a shot =\ – Chase Commented Oct 5, 2012 at 12:54 - I might try your suggestion Chase THX;) – Dejo Dekic Commented Oct 5, 2012 at 12:56
1 Answer
Reset to default 9To bind the load
event to the window, you should use the on
method provided by jQuery.
The .on() method attaches event handlers to the currently selected set of elements in the jQuery object. As of jQuery 1.7, the .on() method provides all functionality required for attaching event handlers.
$(window).on("load", function(){...})
本文标签: javascriptWhat is window load alternativeStack Overflow
版权声明:本文标题:javascript - What is window load alternative? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741661728a2391079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论