【问题标题】:setTimeout function设置超时功能
【发布时间】:2013-01-09 02:03:40
【问题描述】:

我一直在研究我的问题,不想重复发布,但我尝试了研究中描述的方法,但无法延迟我的功能!!

谁能看看我的语法是否有问题以及为什么它不起作用?除了 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);
});

【问题讨论】:

  • 你能在jsfiddle中设置一个演示吗?
  • 您的 setimeout 功能有效。我在里面放了一个console.log('hi'),我看到了。
  • 你隐藏#prevBtn a#nextBtn a然后在setTimeout中淡出它们,你可能打算使用fadeIn (api.jquery.com/fadeIn)
  • 我不希望按钮在加载时显示,这就是为什么我在加载时隐藏它们。当用户将鼠标悬停在滑块上时,按钮就会出现。在鼠标移出时,我希望按钮在 3 秒后淡出..
  • .delay 仅适用于 1.4。我没有用那个

标签: javascript jquery function settimeout


【解决方案1】:
$(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);

    });

});

【讨论】:

  • 同意。我根本没有尝试优化,因为我们不知道他的 html 是什么样的。
  • 嗨 Geuis。你的解决方案成功了。我在我的研究中找不到任何地方。谢谢你和大家的帮助。 :)
【解决方案2】:

您的 setimeout 功能有效。我放了一个

console.log('hi');

在里面,我看到了。

我认为您需要删除这些行,因为它会使隐藏在 dom 上的元素准备就绪。

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

【讨论】:

    猜你喜欢
    • 2022-10-05
    • 2012-01-06
    • 1970-01-01
    • 2016-10-30
    • 1970-01-01
    • 2016-11-29
    • 2019-01-27
    • 2017-10-19
    • 2012-08-26
    相关资源
    最近更新 更多