摇动效果杀死焦点 [英] Shake effect kills focus

查看:81
本文介绍了摇动效果杀死焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery震动效果似乎杀死了被震动元素的焦点。例如(参见 http://jsfiddle.net/xSNBp/

The jQuery shake effect seems to kill focus of the element being shaked. For example (see http://jsfiddle.net/xSNBp/)

$('input')。focus()。effect('shake',{times:3,distance:2},30);

杀死焦点。这是一个错误吗?我的问题是,当触发震动效果时,我不知道当前聚焦的是什么元素,所以我无法重新聚焦它。有什么建议吗?

kills the focus. Is this a bug? My problem is that I don't know what element is currently focused when the shake effect is triggered, so I can't refocus it. Any suggestions?

(如果这是一个错误,我该怎么办?)

(If this is a bug, what should I do?)

推荐答案

我们最近将提交推送到master / 1.8修复一些效果的焦点问题。你是否尝试过使用git的jQuery UI版本?甚至UI 1.8.16?

We very recently pushed a commit to master / 1.8 to fix focus issues with some effects. Have you tried this using the version of jQuery UI from git? Or even UI 1.8.16?

请参阅 http://bugs.jqueryui.com / ticket / 7595 找到了修复该错误的错误。

See http://bugs.jqueryui.com/ticket/7595 for the bug that called for that fix.

这是一个解决方法,应该在较旧的1.8代码中为您修复它:

Here is a workaround that should fix it for you in older 1.8 code:

function doShake( elem, opts, duration ) {
    var active = document.activeElement;
    elem.effect( "shake", opts, duration, fixFocus );
    fixFocus();

    function fixFocus() {
       if ( active === elem[0] || $.contains( elem[0], active ) ) {
           $( active ).focus();
       }
    }
}

如果不是您遇到的问题,请告诉我们错误跟踪器。

If this wasn't the problem that you were experiencing, please let us know on the bug tracker.

发生这种情况的原因是当您包装或将焦点元素附加到其他地方时在DOM中 - 它失去了它的焦点。所以我们必须在 createWrapper removeWrapper 中添加一个检查以保持焦点。

The reason it is happening is that when you "wrap" or append a focused element to someplace else in the DOM - it loses its focus. So we had to add a check to the createWrapper and removeWrapper to retain the focus.

这篇关于摇动效果杀死焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆