admin管理员组

文章数量:1399136

I have something like this:

var isAnimating = 'no';
$('.big-slider-button img').click(function(e){

                if(isAnimating=='no')
                    {
                    isAnimating = 'yes';
                    setTimeout(isAnimating = 'no',30000);
                var img_nr = $(this).attr('description');
                if(img_nr!='0')
                {
                    var image = $('.billboard').attr('src');
                    var new_image = (image.substr(0,image.length-9))+img_nr+"-big.png";
                    $(".billboard").fadeOut(1000, function() {
                        $(this).attr('src',new_image);
                        $('.big-slider-button img').attr('description',parseInt(img_nr)-1);
                        $('.big-slider-button-right img').attr('description',parseInt(img_nr)+1);
                    }).fadeIn(1000);
                }}

            });

but it's not working. I set timeout on 30000 on purpose to see if it's working but it's not. Can anyone tell me what am I doing wrong? Thank you all in advance for your help.

EDIT: THANK YOU ALL FOR YOUR ANSWERS. I'M A BIT NEW WITH JQUERY, SO SORRY IF MY QUESTION IS STUPID.

I have something like this:

var isAnimating = 'no';
$('.big-slider-button img').click(function(e){

                if(isAnimating=='no')
                    {
                    isAnimating = 'yes';
                    setTimeout(isAnimating = 'no',30000);
                var img_nr = $(this).attr('description');
                if(img_nr!='0')
                {
                    var image = $('.billboard').attr('src');
                    var new_image = (image.substr(0,image.length-9))+img_nr+"-big.png";
                    $(".billboard").fadeOut(1000, function() {
                        $(this).attr('src',new_image);
                        $('.big-slider-button img').attr('description',parseInt(img_nr)-1);
                        $('.big-slider-button-right img').attr('description',parseInt(img_nr)+1);
                    }).fadeIn(1000);
                }}

            });

but it's not working. I set timeout on 30000 on purpose to see if it's working but it's not. Can anyone tell me what am I doing wrong? Thank you all in advance for your help.

EDIT: THANK YOU ALL FOR YOUR ANSWERS. I'M A BIT NEW WITH JQUERY, SO SORRY IF MY QUESTION IS STUPID.

Share Improve this question edited Sep 10, 2013 at 13:35 Marko Vasic asked Sep 10, 2013 at 13:18 Marko VasicMarko Vasic 69010 silver badges27 bronze badges 1
  • No research effort... developer.mozilla/en-US/docs/Web/API/window.setTimeout – Ian Commented Sep 10, 2013 at 13:20
Add a ment  | 

3 Answers 3

Reset to default 6

setTimeout

 setTimeout(function(){ isAnimating = 'no' },30000);

you need to pass a callback function

setTimeout(function(){
    isAnimating = 'no'
},30000);

The first argument to setTimeout is a piece of code you want to run when the specified amount of time has passed. In Javascript, units of executable code have to be passed as functions, so you'll want to create a function that does whatever you want to do in 30s.

setTimeout(function(){ isAnimating = 'no'; }, 30000);

You can also simply pass the name of a function (without parenthesis) to have it execute after the timeout, like so:

doStuff = function(){ isAnimating = 'no'; };
setTimeout(doStuff , 30000);

Also, be sure that isAnimating is global, if you're hoping to set a local variable on an object using this method, you'll need some way to access it from the global scope. Check out this Q&A for more information about scopes and closures: How to solve Var out of scope within setTimeout call

Hope this helps!

本文标签: javascriptsetTimeout not working setted to 30000but not workingStack Overflow