2013-01-09 53 views
1

我一直在研究我的问题,不想发布重复,但我已经尝试了我的研究中描述的方法,无法让我的函数延迟!setTimeout函数

有人可以看看,让我知道,如果我的语法有问题,为什么它不起作用?一切运行除了setTimeout函数

$(document).ready(function(){ 
    $("#slider").easySlider({ 
     auto: true, 
     continuous: true 
    }); 

    $("#prevBtn a").hide(); 
    $("#nextBtn a").hide(); 
    $("#slider").mouseover(function(){ 
     $("#prevBtn a").show(); 
     $("#nextBtn a").show(); 
    }); 

    setTimeout(function(){ 
     $("#prevBtn a").fadeOut('slow'); 
     $("#nextBtn a").fadeOut('slow'); 
    },3000); 
}); 
+0

你能设置在[的jsfiddle]演示(http://jsfiddle.net/)? – dunli

+0

您的setimeout功能有效。我在里面放了一个console.log('hi'),我看到了它。 –

+4

你隐藏了'#prevBtn a'和'#nextBtn a',然后在setTimeout中淡出它们,你可能是想用fadeIn(http://api.jquery.com/fadeIn/) – Gabriel

回答

4
$(document).ready(function(){ 
    $("#slider").easySlider({ 
     auto: true, 
     continuous: true 
    }); 

    $("#prevBtn a").hide(); 
    $("#nextBtn a").hide(); 
    $("#slider").mouseover(function(){ 
     $("#prevBtn a").show(); 
     $("#nextBtn a").show(); 
    }) 
    .mouseout(function(){ 

     setTimeout(function(){ 
      $("#prevBtn a").fadeOut('slow'); 
      $("#nextBtn a").fadeOut('slow'); 
     },3000); 

    }); 

}); 
+0

同意。我没有尝试优化,因为我们不知道他的html是什么样的。 – Geuis

+0

嗨Geuis。你的解决方案做到了。在我的研究中,我找不到任何地方。谢谢大家的帮助。 :) – Jgunzblazin

1

你setimeout功能工作良好。我把

console.log('hi'); 

里面,我看到它。

我想你需要删除这些行,因为它会使元素隐藏在DOM准备就绪。

$("#prevBtn a").hide(); 
$("#nextBtn a").hide();