自从我安装了 Adblock Plus for firefox(用于阻止广告的附加组件)后,由 scriptaculous 提供支持的每个动画都不再起作用(不仅在我的网站上)。
现在我知道了,我正在寻找一种方法来检查 JavaScript 函数是否未完成(就像我为脚本动画调用的函数)。
<script type="text/javascript">
function scriptaculous(){
new Effect.Morph("thumb_id", { style: "height:300px;", duration: 0.8 });
}
function enlarge_thumbnail(){
scriptaculous();
// if( scriptaculous() was not completed ){
document.getElementById("thumb_id").style.height = "300px";
// }
}
</script>
真正的问题是我不能只调用它们两个,因为第一个错误并阻止第二个加载。有谁知道如何处理吗?
最佳答案
每当任何效果启动等时,它们都会添加到全局效果队列中,因此您可以检查队列是否存在以及队列中有多少效果。
if(Effect.Queues.get('global').effects.length == 0)
{
//do something else
}
此外,由于 Effects 方法将立即返回,因此您无法确切知道效果何时完成,除非您像这样使用 afterFinish
回调
new Effect.Morph("thumb_id",
{
style: "height:300px;",
duration: 0.8,
afterFinish: function(effect){
//do other things when the effect is finished
//the callback is passed the effect object
//and the element it is working on is at effect.element
} });
关于javascript - 检查 javascript 函数是否未完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16943346/