为什么幻灯片被调用两次(间歇性问题)?
我有一个称为幻灯片的功能,其中包含附加任务/步骤。函数内的上滑代码间歇性地被调用两次。有人能发现我做错了什么吗?
全局变量
var currIndex = 0;
有问题的函数
function PreNext(direction) {
alert('Test #1');
var thisMaxlen = homes.length - 1; // homes is an array.
var ctrl_toolTip = $('#controlSlideShow .tooltip');
$(ctrl_toolTip).slideUp('slow' function () {
alert('Test #2');
if (direction == 'Next') {
(currIndex >= thisMaxlen ? currIndex = 0 : currIndex++);
}
else {
(currIndex <= 0 ? currIndex = thisMaxlen : currIndex--);
}
});
alert('Test #3');
};
间歇性地调用两次幻灯片。
结果
Test #1
Test #2
Test #2
Test #3
I have a function which I call the slideup with additional tasks/steps. Intermittently, the slideup code within the function is called twice. Can someone spot what I did wrong?
Global Variable
var currIndex = 0;
The function with the issue
function PreNext(direction) {
alert('Test #1');
var thisMaxlen = homes.length - 1; // homes is an array.
var ctrl_toolTip = $('#controlSlideShow .tooltip');
$(ctrl_toolTip).slideUp('slow' function () {
alert('Test #2');
if (direction == 'Next') {
(currIndex >= thisMaxlen ? currIndex = 0 : currIndex++);
}
else {
(currIndex <= 0 ? currIndex = thisMaxlen : currIndex--);
}
});
alert('Test #3');
};
Intermittently, the slideup is called twice.
The result
Test #1
Test #2
Test #2
Test #3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想到的唯一原因是您在
ctrl_toolTip
中获得了多个元素,只需确保
$('#controlSlideShow .tooltip');
仅返回单个元素元素。The only reason that come to my mind is that you are getting more then one elements in
ctrl_toolTip
Just make sure that
$('#controlSlideShow .tooltip');
returns only single element.好的。我无法弄清楚为什么会发生双重传递。不过,我能够采取一种解决方法来适应双通道。
Ok. I wasn't able to figure why the double pass was occurring. However I was able to put in a workaround to accommodate the double pass.