是否有一种方法来动画文本区域的不透明度与jQuery

Is there a way to animate the opacity of textarea with jQuery?

本文关键字:区域 文本 动画 不透明度 jQuery 方法 一种 是否      更新时间:2023-09-26

我需要在textarea中设置文本的不透明度,这样它就会逐渐消失。当有人按回车键时就会发生这种情况。我已经为回车键设置了代码,但不能让代码动画工作。下面是我的代码:

$(document).keydown(function(e){
if(e.which === 13){
// here I would like to animate the text
   };
});

对于仅文本,我认为您需要jQueryUI,并执行如下操作:

$("#textarea").keydown(function(e){
    if(e.which === 13){
        $(this).animate({color: 'transparent'},1000);
   }
});

这里有一个小提琴:http://jsfiddle.net/adeneo/7pkNK/

请注意,光标也会消失,据我所知,唯一的方法是用动画gif或其他自定义代码创建光标。

    $(document).keydown(function(e){
     if(e.which === 13){
      $(formelement).animate({ color: "#FFFFFF" }, 600);
   };
});

这个来自JQuery API的例子会有帮助吗?

<div id="clickme">
   Click here
</div>
<img id="book" src="book.png" alt="" width="100" height="123" />
$('#clickme').click(function() {
  $('#book').fadeOut('slow', function() {
    // Animation complete.
  });
});

查看。fadein()和。fadeto()的API。

在您的例子中,您可以使用$('#text').fadeOut();

尝试使用jQuery的fadeOut方法。

$(document).keydown(function(e) {
    var code = (e.keyCode ? e.keyCode : e.which);
    if (code === 13) {
        //here i would like to animate the text
        $('#idofobject').fadeOut(optionalduration, optionalcallback);
    }
});

我将检索使用我的代码的第二行按下的键,根据这个SO答案。


看了你对@dremme的评论后,我不相信有一种方法可以让褪色,只是文本很简单。你必须在你的文本区域上方放置一个div,删除当前在文本区域中的文本,并淡出你的覆盖div。