javascript - 淡入前预对焦输入框

标签 javascript jquery html textinput

我有两个输入字段。第二个 input 开始聚焦。然后我想 fadeOut 两个 input,让第二个 input 保持专注直到结束。最后,我想 fadeIn 两个 input 并以 first input 为焦点结束。

但是,我不想看到“故障”,即第二个 inputfadeIn 完成后瞬间获得焦点,然后是第一个 input 紧随其后。

这是我尝试过的(参见 fiddle here ):

// Focus the second input field
$('input').eq(1).focus();

// Fade out both input fields
$('div').fadeOut();

// Fade in both input fields
$('div').fadeIn(function () {
    // Causes a "transition glitch"
    $('input').eq(0).focus();
});

有没有办法“预聚焦”第二个 input 字段?

最佳答案

怎么样:

// Focus the second input field
$('input').eq(1).focus();

// Fade out both input fields
$('div').animate({'opacity': 0}, function() {
    $('input').eq(0).focus();

    // Fade in both input fields
    $('div').animate({'opacity': 1});​
});

关于javascript - 淡入前预对焦输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14114459/

相关文章:

javascript - 在turn.js中设置第一页是双页而不是单页?

html - 如何在div的底部制作一个三 Angular 形

html - 向下滚动页面时背景图像不是 100% 高度

javascript - D3JS 测试 - enter() 未被触发

javascript - Jquery 对话框中的单选按钮

javascript - 分形螺旋图 : possible rounding errors in javascript

javascript - 如何在不刷新页面的情况下更改 URI?

jquery - 将鼠标悬停动画添加到 HTML5 Canvas 绘图中的问题

html - 设置溢出-x : hidden adds a vertical scrollbar

javascript - 神经网络连续 tanh-Sigmoid 激活函数和随机权重