如何在页面 运行ning 时使我的函数变为 运行?

How can I make my function to run the moment the page is running?

我想在用户加载我的页面时创建一个功能 运行。没有交互性。当有人点击时,该功能正在加载。我还想在 1 分半钟后使函数循环。我尝试将 "click" 替换为 window.onload 和 body.onload,但正如您现在可能已经注意到的那样,我是 javascript 的真正初学者。有人可以帮我一下吗?现在我只有这个:

// Animate an element by adding a class to it:
// Paramaters: 
// anim: the class name to add
// time: animation duration (optional, fallsback to the class)
// cb: an optional callback function to happen once the animation ends
$.fn.animatecss = function(anim, time, cb) {

    if (time) this.css('-webkit-transition', time / 1000 + 's');
    this.addClass(anim);

    if ($.isFunction(cb)) {
        setTimeout(function() {
            // Ensure that the element is available inside the callback.
            $(this).each(cb);
        }, (time) ? time : 5000);
    }

    return this;
};

$(document).ready(function() {
    $('.box')click(function() {
        $(this).animatecss('blur-out', 5000, function() {
            console.log('callback');
        });
    });
});
.blur-out {
    -webkit-filter: blur(8px);
    -webkit-transform: scale(1.4, 1.4);
    -webkit-transition: all 5s ease-out;
    transition: all 5s ease-out;
    visibility: hidden;
}

.box {    
    background:#fff;  
    margin: 80px; 
   padding: 20px;    
    
}
    
<div class="box">
    <img src="http://companionplants.com/images/small-plant2.jpg">
</div>

$(document).ready(function() {
    $('.box').click(function() {
        $(this).animatecss('blur-out', 5000, function() {
            console.log('callback');
        });
    });

    // add this line
    $('.box').trigger('click');
});

参考:http://api.jquery.com/trigger/

如果我没理解错的话,你想在页面加载后自动启动动画。

删除点击事件处理程序。像这样留下动画代码:

$(document).ready(function() {  
        
  $('.box').animatecss('blur-out', 5000, function() {
    
    console.log('callback');
    
  });

            
});

为了自动重复此代码,您需要将此代码放在带有 settimeout() 的递归函数中。

$(document).ready(function() {
  
  function animate(){
    $('.box').animatecss('blur-out', 5000, function() {
      
      console.log('callback');

    });
            
    setTimeout( animate(), 60000);
  }
  
  animate();
            
});

希望没有错误,我现在无法查看,但我想它会对你有所帮助