jquery hover延时

时间:2020-12-23 19:04:25

var timer;
    //绑定hover事件
    $(function () {
         $(".centercy img").hover(showPic, hidePic);
    });

//显示图片
    function showPic() {
        var el = $(this),
                imgUrl = "url('" + el.attr("big-img") + "')";
        timer = setTimeout(function () { $("#photo").css("background-image", imgUrl).slideDown(200) }, 210);
    }
    //隐藏图片
    function hidePic() {
        clearTimeout(timer);
        $("#photo").hide();
    }