Tommy
Tommy

Reputation: 21

Why is the slideup called twice (intermittent issue)?

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

Upvotes: 1

Views: 505

Answers (2)

Tommy
Tommy

Reputation: 21

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');
      };

Upvotes: 1

Talha Ahmed Khan
Talha Ahmed Khan

Reputation: 15453

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.

Upvotes: 1

Related Questions