Trigger event on body load complete js/jquery

前端 未结 10 1798
眼角桃花
眼角桃花 2020-12-05 18:36

I want to trigger one event on page load complete using javascript/jquery.

Is there any way to trigger event or call a simple function once page loading fully comple

10条回答
  •  借酒劲吻你
    2020-12-05 19:10

    The windows.load function is useful if you want to do something when everything is loaded.

    $(window).load(function(){
        // full load
    });
    

    But you can also use the .load function on any other element. So if you have one particularly large image and you want to do something when that loads but the rest of your page loading code when the dom has loaded you could do:

    $(function(){
        // Dom loaded code
    
        $('#largeImage').load({
            // Image loaded code
        });
    });
    

    Also the jquery .load function is pretty much the same as a normal .onload.

提交回复
热议问题