www.webdeveloper.com
Results 1 to 8 of 8

Thread: clearInterval does not work

Hybrid View

  1. #1
    Join Date
    Apr 2013
    Posts
    7

    Question clearInterval does not work

    Hey guys,

    I've done a d&d script.
    But if the interval is going since a few minutes, the d&d is lagging.
    So I made a function which should clear the interval, but it is not working.
    Here is the code:
    Code:
    var qwindow = function() {
    ...
                    this.interval;
    ...
                    this.move = function(e, target) {
    ...
                                this.interval = window.setInterval( function() {
    ...
                                }, 50);
                    }
                    this.stop = function() {
                        window.clearInterval(interval);
                    } 
                    this.start = function(e, target) {
    ...
                    }
                    this.remove = function() {
    ...
                    }
                }
                    this.stop = function() {
                        window.clearInterval(this.interval);
                    } 
    }
    mfg, deSpeach

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    You have show two stop methods, the second of which doesn't seem to be part of the object declaration. The one that is, is being passed the wrong parameter.

  3. #3
    Join Date
    Apr 2013
    Posts
    7
    At first thanks for your fast reply.
    I just failed @ copy & paste, in real it's just one function.
    And the error with the parameter was created while I tried too fix the bug.
    I changed it too
    window.clearInterval(this.interval);
    And it's still not working

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by deSpeach View Post
    At first thanks for your fast reply.
    I just failed @ copy & paste, in real it's just one function.
    And the error with the parameter was created while I tried too fix the bug.
    I changed it too

    And it's still not working
    I suspect a scope issue. Can you show how your stop method is called?

  5. #5
    Join Date
    Apr 2013
    Posts
    7
    Here is the code of the stop method:
    Code:
    this.stop = function() {
                         window.clearInterval(this.interval);
                    }
    This function is triggering the qwindowa[qid].stop(); function
    Code:
    $('body').mouseup(function() {
                        if(click == true) {
                            qwindowa[qid].stop();
                            click = false;
                        }
                    });
    And in this function is the interval starting:
    Code:
    this.move = function(e, target) {
                                this.interval = window.setInterval( function() {
                                        ...
                                }, 100);
                    }
    And this function's defining the
    Code:
    $('body').on('mousedown', '*', function(e) {
                        if($(this).attr('id').indexOf('_windowq') == -1)
                            return;
                        else {
                            click = true;
                            qid = $(this).attr('id').replace('_windowq', '');
                            qtarget = $(this);
                            qwindowa[$(this).attr('id').replace('_windowq', '')].start(e, $(this));
                            $('body').attr('unselectable', 'on');
                        }
                    });

  6. #6
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Still difficult to visualise, but what happens if you do this:
    Code:
    this.move = function(e, target) 
    {
       this.stop();
    
       this.interval = window.setInterval( function() 
       {
           ...    
       }, 100); 
    }

  7. #7
    Join Date
    Apr 2013
    Posts
    7
    And this function's defining the "qid" variable (I dont find the edit button...)

  8. #8
    Join Date
    Apr 2013
    Posts
    7
    It's still not working..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles