以下是代码:
$("#textyt:input").focus(function() {
$(this).animate({width:"545px"},500).css("color","#614A3E");
$(this).select();
$(this).mouseup(function(e){
e.preventDefault();
});
});
如果我带走了动画效果,这个焦点事件会选择文字(我喜欢)。使用动画效果,文本会在Firefox中完成动画的取消选择。这在Safari中可以正常工作。有没有办法确保动画在FF结束时仍然选择文本?谢谢!
答案 0 :(得分:3)
尝试使用:
this.focus();
this.select();
动画后。
这将在动画完成后选择文本。 宽度动画通过动态更改CSS宽度属性来工作,并且可能在firefox中失去焦点,但更好的想法是更改容器元素的宽度,而不是实际的textarea。
$("#textyt:input").focus(function() {
$(this).animate(
{width:"545px"}, 500, function(){
this.focus();
this.select();
}).css("color","#614A3E");
$(this).select();
$(this).mouseup(function(e){
e.preventDefault();
});
});