为什么幻灯片被调用两次(间歇性问题)?

发布于 2024-11-27 09:12:57 字数 824 浏览 1 评论 0原文

我有一个称为幻灯片的功能,其中包含附加任务/步骤。函数内的上滑代码间歇性地被调用两次。有人能发现我做错了什么吗?

全局变量

    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 技术交流群。

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

发布评论

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

评论(2

酒绊 2024-12-04 09:12:57

我想到的唯一原因是您在 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.

淡写薰衣草的香 2024-12-04 09:12:57

好的。我无法弄清楚为什么会发生双重传递。不过,我能够采取一种解决方法来适应双通道。

    function PreNext(direction) {
        alert('Test #1');
        var dblPassFix = 0;                 // To fix the double pass in the slideup
        var thisMaxlen = homes.length - 1;  // homes is an array.
        var ctrl_toolTip = $('#controlSlideShow .tooltip');

        $(ctrl_toolTip).slideUp('slow' function () {
            alert('Test #2');
            dblPassFix++;

            if (direction == 'Next') {
                (currIndex >= thisMaxlen ? currIndex = 0 : currIndex++);

                if (dblPassFix > 1) {
                    currIndex--;
                }
                ...
            }
            else {
                (currIndex <= 0 ? currIndex = thisMaxlen : currIndex--);

                if (dblPassFix > 1) {
                    currIndex++;
                }
                ...
            }
        });
        alert('Test #3');
      };

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.

    function PreNext(direction) {
        alert('Test #1');
        var dblPassFix = 0;                 // To fix the double pass in the slideup
        var thisMaxlen = homes.length - 1;  // homes is an array.
        var ctrl_toolTip = $('#controlSlideShow .tooltip');

        $(ctrl_toolTip).slideUp('slow' function () {
            alert('Test #2');
            dblPassFix++;

            if (direction == 'Next') {
                (currIndex >= thisMaxlen ? currIndex = 0 : currIndex++);

                if (dblPassFix > 1) {
                    currIndex--;
                }
                ...
            }
            else {
                (currIndex <= 0 ? currIndex = thisMaxlen : currIndex--);

                if (dblPassFix > 1) {
                    currIndex++;
                }
                ...
            }
        });
        alert('Test #3');
      };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文