使用 mootools 1.4.1 的代码会导致无限循环

发布于 2024-12-12 06:28:34 字数 2724 浏览 4 评论 0原文

我正在使用 mootools 1.4.1,并且我正在尝试获取一个可以“补间”屏幕宽度的 div,以便在完成时触发另一个函数。然而,补间不断​​触发,我不相信它正在触发我想要的功能。

代码如下:

$('photo-loading_amt').set('tween', {duration: '1000ms',
                                     link: 'cancel',
                                     transition: 'linear',
                                     property: 'width',
                                     onComplete: function() {
                                                   var photoContainers = $$('.photo-container')

                                                   if (photoNum != photoContainers.length)  {
                                                       nextPhoto(photoNum.toInt() + 1);
                                                   }
                                                   else {
                                                       nextPhoto(1);
                                                   }    
                                                 }
                           });

如果您有任何帮助,我们将不胜感激。

@Dimitar Christoff,这是 nextPhoto 函数的代码:

function nextPhoto(photoNum)    {
resetTimeline();

var photoContainers = new Array();

photoContainers = $$('.photo-container');

var photoFx = new Fx.Tween(photoContainers[photoNum.toInt() - 1], {
                                duration: 'normal',
                                transition: Fx.Transitions.Sine.easeOut,
                                property: 'opacity',

                                onComplete: function() {
                                                            photoContainers[photoNum.toInt() - 1].setStyle('visibility', 'hidden');
                                                            photoContainers[photoNum.toInt() - 1].setStyle('opacity', 1);

                                                            if (photoNum == photoContainers.length) {
                                                                photoContainers[0].setStyle('z-index', photoContainers.length);
                                                            }
                                                        }
                            });

if (photoNum == photoContainers.length) {
    photoContainers[0].setStyle('z-index', 0);
}

photoFx.tween(1, 0);
//alert("photoNum = " + photoNum + "\n" + "photoContainers.length = " + photoContainers.length);
if (photoNum == photoContainers.length) {
    photoContainers[0].setStyle('visibility', 'visible');       
}
else    {
    photoContainers[photoNum.toInt()].setStyle('visibility', 'visible');
    //loadingPhotos(photoNum.toInt() + 1);
}
// hard reset the loadingPhotos function    

} // FUNCTION nextPhoto 的结尾

I'm using mootools 1.4.1 and I'm trying to get a div that 'tweens' the width of the screen to fire another function on completion. However, the tween keeps firing and I don't believe that it's firing the function I'm wanting it to.

The code is below:

$('photo-loading_amt').set('tween', {duration: '1000ms',
                                     link: 'cancel',
                                     transition: 'linear',
                                     property: 'width',
                                     onComplete: function() {
                                                   var photoContainers = $('.photo-container')

                                                   if (photoNum != photoContainers.length)  {
                                                       nextPhoto(photoNum.toInt() + 1);
                                                   }
                                                   else {
                                                       nextPhoto(1);
                                                   }    
                                                 }
                           });

Any Help that you might have would be appreciated.

@Dimitar Christoff, here's the code for the nextPhoto function:

function nextPhoto(photoNum)    {
resetTimeline();

var photoContainers = new Array();

photoContainers = $('.photo-container');

var photoFx = new Fx.Tween(photoContainers[photoNum.toInt() - 1], {
                                duration: 'normal',
                                transition: Fx.Transitions.Sine.easeOut,
                                property: 'opacity',

                                onComplete: function() {
                                                            photoContainers[photoNum.toInt() - 1].setStyle('visibility', 'hidden');
                                                            photoContainers[photoNum.toInt() - 1].setStyle('opacity', 1);

                                                            if (photoNum == photoContainers.length) {
                                                                photoContainers[0].setStyle('z-index', photoContainers.length);
                                                            }
                                                        }
                            });

if (photoNum == photoContainers.length) {
    photoContainers[0].setStyle('z-index', 0);
}

photoFx.tween(1, 0);
//alert("photoNum = " + photoNum + "\n" + "photoContainers.length = " + photoContainers.length);
if (photoNum == photoContainers.length) {
    photoContainers[0].setStyle('visibility', 'visible');       
}
else    {
    photoContainers[photoNum.toInt()].setStyle('visibility', 'visible');
    //loadingPhotos(photoNum.toInt() + 1);
}
// hard reset the loadingPhotos function    

} // end of FUNCTION nextPhoto

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断爱 2024-12-19 06:28:34

由于我在您的代码中没有看到明显的循环,因此我怀疑该效果是由

link: 'cancel'

您的第一个代码块引起的。根据 Moo 文档,这将:

“取消”- 效果运行时启动的任何调用都将优先于当前运行的过渡。新的转换将立即开始,取消当前正在运行的转换。

所以这可能会让你的孩子感到不安。但是,您可能是故意添加的。我会尝试在第一个和第二个补间设置中将其更改为 chainignore,以查看最佳组合。
如果这不能解决问题,也许您可​​以发布更多代码。例如,我没有看到 resetTimeline 函数的代码。也许你的代码被卡在这里了。

Since I don't see an apparent loop in your code, I would suspect the effect to be caused by

link: 'cancel'

in your first block of code. According to the Moo docs this will:

'cancel' - Any calls made to start while the effect is running will take precedence over the currently running transition. The new transition will start immediately, canceling the one that is currently running.

So this might upset your tweens. However, you probably added this deliberately. I would try changing this to chain or ignore, both in your first and second tween setup, to see what combines best.
If this doesn't solve it, perhaps you could post some more code. For instance, I don't see the code for the resetTimeline function. Perhaps your code gets stuck here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文