什么是窗户装载替代品? [英] What is window load alternative?

查看:132
本文介绍了什么是窗户装载替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下情况:我只想在页面完全加载时显示我的图像 因为我想避免在内部逐个显示图像 文档就绪功能 (它们最初是隐藏的,只想在文档加载完毕后立即显示 ),所以我使用 $(窗口).load(function(){});


当我使用此函数时,它运行正常并且行为符合预期,但是我唯一的问题是加载函数已弃用

例如,如果我使用下面的代码没有 $(窗口).load 我可以看到我的图像加载了一个一个不是一个选项(setTimeout也没有选项)。

我的问题:如何在不使用 $(窗口).load 的情况下实现相同的行为?谢谢!!

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!!

示例代码:

$(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();
   });

});


推荐答案

绑定 loading 到窗口的事件,您应该使用 on 方法由jQuery提供。

To bind the load event to the window, you should use the on method provided by jQuery.


.on()方法将事件处理程序附加到当前选定的集合$ b jQuery对象中的$ b元素。从jQuery 1.7开始,.on()方法
提供了附加事件处理程序所需的所有功能。

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(){...})

这篇关于什么是窗户装载替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆