使用 mootools 1.4.1 的代码会导致无限循环
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于我在您的代码中没有看到明显的循环,因此我怀疑该效果是由
您的第一个代码块引起的。根据 Moo 文档,这将:
所以这可能会让你的孩子感到不安。但是,您可能是故意添加的。我会尝试在第一个和第二个补间设置中将其更改为
chain
或ignore
,以查看最佳组合。如果这不能解决问题,也许您可以发布更多代码。例如,我没有看到
resetTimeline
函数的代码。也许你的代码被卡在这里了。Since I don't see an apparent loop in your code, I would suspect the effect to be caused by
in your first block of code. According to the Moo docs this will:
So this might upset your tweens. However, you probably added this deliberately. I would try changing this to
chain
orignore
, 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.