Javascript Jquery:在完成'之后;淡入';效果,等待';单击';事件

Javascript Jquery:在完成'之后;淡入';效果,等待';单击';事件,javascript,jquery,html,css,Javascript,Jquery,Html,Css,如何等待单击事件? 例如,我希望我的在淡入后等待3秒钟,如果在3秒钟内未单击,则淡出 我试图给时间2秒的淡出,但鼠标点击不工作,它只是淡出 my.js文件代码: $(document).ready(function () { $(".arrow").hide() $(".container").mouseenter(function () { $(".arrow").fadeIn() }); $(".container").mouseleave(function () { $

如何等待单击事件? 例如,我希望我的
在淡入后等待3秒钟,如果在3秒钟内未单击
,则淡出

我试图给时间2秒的淡出,但鼠标点击不工作,它只是淡出

my.js文件代码:

$(document).ready(function () {
$(".arrow").hide()

$(".container").mouseenter(function () {
    $(".arrow").fadeIn()
});

$(".container").mouseleave(function () {
    $(".arrow").fadeOut(2000)
});

$(".arrow").click(function () {
    $(".container").hide()
});

我不确定您想要完成什么,但您的onClick处理程序无法工作,因为语法错误

试试这个:

$(".arrow").on('click', function () {
    $(".container").hide()
});
另外,您似乎缺少
ready
-函数的右括号

应该是这样的:

$(document).ready(function () {

 // Your code here

}); // Don't forget this line

使用布尔值检查是否在时间限制结束时单击了箭头


好的@Eshwer这里是代码^
$(document).ready(function () {

 // Your code here

}); // Don't forget this line
$(document).ready(function () {
    var clicked = false;

    $(".arrow").click(function () {
        clicked = true;
    });

    $(".container").hover(function () { // i put the two mouseenter, mouseleave functions into one hover(mousein, mouseout) function
        $(".arrow").fadeIn();
        setTimeout(function () {
            if (clicked === false) {
                $(".arrow").fadeOut(2000);
            }
        }, 3000);
    }, function () {
        $(".arrow").fadeOut(2000);
        clicked = false; // i don't know if you want this or not. this resets everything on mouseout. if you want the .arrow thing to stay even after the mouse leaves .container, just get rid of this line
    }); // .hover
}); // .ready