Make jquery function run on page load

拜拜、爱过 提交于 2019-12-04 23:08:35
(function($) {
    $(document).ready(function() {
        window.pulse_image = $('.pulse_image');
        window.pulse_continue_loop = true;
        PulseAnimation(); // start the loop
    });
})(jQuery);​

I don't see why you couldn't just remove the code relating to the mouseover and mouseout events. If by "page load" you mean when the HTML document is loaded, try this:

$(document).ready(function() {
    window.pulse_image = $('.pulse_image');
    window.pulse_continue_loop = true;
    PulseAnimation();
});

If by "page load" you mean when all the images on a page have also loaded then try this:

$(window).load(function() {
    window.pulse_image = $('.pulse_image');
    window.pulse_continue_loop = true;
    PulseAnimation();
});

The latter code example will wait until all images have finished loading. This will trigger via the window being "loaded". Rather, the first code example shows the document being ready which means that the document has been loaded, but not all the resources related to the document have as well.

  $(document).ready(function() {
    window.pulse_continue_loop = true;
    window.pulse_image = $('.pulse_image');
    PulseAnimation(); // start the loop
  });

Here is the way How I did it:

    <script type="text/javascript">
    $(document).ready(function () {
        alert('Document Ready'); 
        $("#imgPreview").attr('src', '/Upload/Upload_Image.png');
    });
</script>

Here is a variation that loads default data with an ajax call when the page loads.

$(document).ready(function() {

    $.ajax({
        type: 'post',
        url: 'include/ajax.php',
        data: $('#search_filters').serialize(),
        success: function (response) {
            $('#search_display').html(response);
        }
    });

});
dsa

There are many ways to make that effect but one I figured out fastest is

 setTimeout(function(){
     $(".pulse_image").trigger('mouseover');
 }, 1300);

this is not the best solution for sure but it will do the "trick" ... just add this into document.ready callback.

  $(document).ready(function() {
    window.pulse_continue_loop = true;
    window.pulse_image = $('.pulse_image');
    setTimeout(function(){
      PulseAnimation();
    } // start the loop
  });

you can try this way also. this will trigger whenever your page is loading.

function pageLoad(sender,args) {
// call your function
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!