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
3 Answers
Reset to default 6setTimeout
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
版权声明:本文标题:javascript - setTimeout not working setted to 30000, but not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744138985a2592533.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论