How can I call clearInterval outside of a function in jQuery? Outside the setInterval

TheBlackBenzKid
    function iPadMovie(id) {
    $(function () {
        var i = 1;
        var interval = setInterval(function () {
            jQuery('.animationMax img').attr({
                src: 'http://jdsports.scene7.com/is/image/JDSports/127932jd' + ('0' + i).slice(-2) + '?hei=255&wid=427&resmode=sharp&op_usm=1.1,0.5,0,0&defaultImage=JDSports/sizeImageMissing'
            });
            i++;
            if (i === 28) i = 1;
        }, 100);
    });
}

function playIpad(){
    iPadMovie();
}


function stopIpad(){
    clearInterval = interval;
}

You can see the fiddle here: http://jsfiddle.net/Vv2u3/15/ I want to be able to stop the movie and restart it if they press play. Surely I can use clearInterval outside the method?

Khamidulla

Here is example link.

var interval;

function iPadMovie(id) {
    $(function () {
        var i = 1;
        interval = setInterval(function () {
            jQuery('.animationMax img').attr({
                src: 'http://jdsports.scene7.com/is/image/JDSports/127932jd' + ('0' + i).slice(-2) + '?hei=255&wid=427&resmode=sharp&op_usm=1.1,0.5,0,0&defaultImage=JDSports/sizeImageMissing'
            });
            i++;
            if (i === 28) i = 1;
        }, 100);
    });
}

function playIpad(){
    iPadMovie();
}

Little bit explanation here. First of all, your interval variable, (which is actual handler for returned callback function by setInterval) is not visible outside of iPadMovie() function so interval variable should be declared outside of this function. Second you should call clearInterval(handler) function inside of stopIpad() function. More information can be founded here.

function stopIpad(){
    clearInterval(interval);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I call clearInterval outside of a function in jQuery? Outside the setInterval

From Dev

How can I call the jQuery function: animate from outside the html?

From Dev

Can I call function outside viewmodel on knockout?

From Dev

Can I call function outside viewmodel on knockout?

From Dev

clearInterval from outside a function

From Dev

How call variable outside function .each with Jquery?

From Dev

How to Call PHP function outside

From Dev

How can I call a function that is defined outside of a class from inside a class

From Dev

How can I call a function that set sets an outside variable inside a custom component in React Native?

From Dev

How do I call outside function from class in python

From Dev

How do I call a function that is defined inside of require() outside of the require()?

From Dev

How can I call on a parent method from outside the class?

From Dev

jQuery call function outside of defined plugin

From Dev

How can I place text that relates to a foreach function, outside the loop?

From Dev

How can I access variable outside function in javascript?

From Dev

How can I get clientHeight value outside backbone render function?

From Dev

How can I stop the execution of a Python function from outside of it?

From Dev

How can I change the Double value in my dictionary outside the function?

From Dev

How can I get the dimensions of the view outside a function?

From Dev

How I can get the value of "j" for use outside the function?

From Dev

Python- How can I access a variable outside of a function?

From Dev

How can I place text that relates to a foreach function, outside the loop?

From Dev

How can I get clientHeight value outside backbone render function?

From Dev

How can i print the result outside the function in express.js?

From Dev

Call a function outside main ()

From Dev

Call a function outside main ()

From Dev

popup outside of a function call

From Dev

signalR calls a server method and that method calls a callback method ,outside the hub. How can I call client function from that method?

From Dev

How to call a function outside of javascript click event

Related Related

  1. 1

    How can I call clearInterval outside of a function in jQuery? Outside the setInterval

  2. 2

    How can I call the jQuery function: animate from outside the html?

  3. 3

    Can I call function outside viewmodel on knockout?

  4. 4

    Can I call function outside viewmodel on knockout?

  5. 5

    clearInterval from outside a function

  6. 6

    How call variable outside function .each with Jquery?

  7. 7

    How to Call PHP function outside

  8. 8

    How can I call a function that is defined outside of a class from inside a class

  9. 9

    How can I call a function that set sets an outside variable inside a custom component in React Native?

  10. 10

    How do I call outside function from class in python

  11. 11

    How do I call a function that is defined inside of require() outside of the require()?

  12. 12

    How can I call on a parent method from outside the class?

  13. 13

    jQuery call function outside of defined plugin

  14. 14

    How can I place text that relates to a foreach function, outside the loop?

  15. 15

    How can I access variable outside function in javascript?

  16. 16

    How can I get clientHeight value outside backbone render function?

  17. 17

    How can I stop the execution of a Python function from outside of it?

  18. 18

    How can I change the Double value in my dictionary outside the function?

  19. 19

    How can I get the dimensions of the view outside a function?

  20. 20

    How I can get the value of "j" for use outside the function?

  21. 21

    Python- How can I access a variable outside of a function?

  22. 22

    How can I place text that relates to a foreach function, outside the loop?

  23. 23

    How can I get clientHeight value outside backbone render function?

  24. 24

    How can i print the result outside the function in express.js?

  25. 25

    Call a function outside main ()

  26. 26

    Call a function outside main ()

  27. 27

    popup outside of a function call

  28. 28

    signalR calls a server method and that method calls a callback method ,outside the hub. How can I call client function from that method?

  29. 29

    How to call a function outside of javascript click event

HotTag

Archive