javascript - CSS,jQuery - 延迟失去最小高度的焦点

标签 javascript jquery css focus delay

我想在文本区域失去焦点时创建一个延迟。目前我有:

<textarea name="description"></textarea>

我的 CSS 读取

.my-form textarea {
 height: 35px;
}

.my-form textarea:focus {
 min-height: 100px;
}

在此下方有一个单选按钮切换。由于在焦点上添加了额外的像素,它被向下推,但是当试图点击一个按钮时它失去了焦点,高度回到原来的高度,你错过了点击。

有没有办法在失去焦点时创建一个延迟,比如 100 毫秒,刚好足以记录按钮上的点击?

最佳答案

使用 CSS

  .my-form textarea {
        height: 35px;
        transition: height 0.3s ease 1s;
    }

    .my-form textarea:focus {
        min-height: 100px;
    }

使用 JQUERY

 $(document).ready(function () {
            $('.my-form textarea').focusin(function () {
                $(this).css('height', '100px');
            });

            $('.my-form textarea').focusout(function () {
                setTimeout(function () { $('.my-form textarea').css('height', '35px'); }, 500);
            });
        });

关于javascript - CSS,jQuery - 延迟失去最小高度的焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21327131/

相关文章:

javascript - 使用 javascript 在字符串中搜索单词

jquery - 从 ScriptSharp 读取 XML 字符串

javascript - 使用数据值/提取选定的 "Tag"的值

CSS4 Grid-Structural 伪类 polyfill ( :nth-column)

html - 将 svg 图标实现到 web 中

javascript - NodeJS-App - DOM 操作?

javascript - 在 Redux Form 中,如何设置复选框的选中属性的初始值?

javascript - 刚开始使用jwplayer,有几个问题

javascript - 无法从 jQuery Post 返回任何数据

html - 图片和文字之间的空间