jQuery Stop .blur() event when clicking “submit” button

后端 未结 4 1474
暗喜
暗喜 2021-02-07 17:36

I am building a small landing page with a simple demo e-mail signup form. I want to have the form field open up when focused, and then shrink back down on blur.

However

4条回答
  •  -上瘾入骨i
    2021-02-07 17:43

    It isn't the prettiest solution, but it does work. Try this:

    $("#submitbtn").mousedown(function() {
        mousedownHappened = true;
    });
    
    $("#email").blur(function() {
        if (mousedownHappened) // cancel the blur event
        {
            mousedownHappened = false;
        }
        else // blur event is okay
        {
            $("#email").animate({
                opacity: 0.75,
                width: '-=240px'
            }, 500, function() {
            });
    
            // hide submit button
            $("#submitbtn").fadeOut(400);
        }
    });​
    

    DEMO HERE

提交回复
热议问题