.live 和文本区域自动调整大小

发布于 2024-09-16 16:52:44 字数 560 浏览 1 评论 0原文

我正在使用 jquery 的小插件: jquery-plugin-autoresize

但我在 .live 中使用它时遇到问题。

有谁知道该怎么做?

我尝试过

$('textarea .blog_comment').live('autoResize', function(e,{
// On resize:
onResize : function() {
$(this).css({opacity:0.8});
},
// After resize:
animateCallback : function() {
$(this).css({opacity:1});
},
// Quite slow animation:
animateDuration : 300,
// More extra space:
extraSpace : 40
}){});;

但行不通。 请帮忙。谢谢/

I am using small plugin to jquery:
jquery-plugin-autoresize

But i have trouble with using it with .live.

Does anyone know how to do it?

I tried

$('textarea .blog_comment').live('autoResize', function(e,{
// On resize:
onResize : function() {
$(this).css({opacity:0.8});
},
// After resize:
animateCallback : function() {
$(this).css({opacity:1});
},
// Quite slow animation:
animateDuration : 300,
// More extra space:
extraSpace : 40
}){});;

But it won't work.
Please help. Thank you/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只怪假的太真实 2024-09-23 16:52:44

您需要在元素再次准备好后重新运行插件,例如在您正在使用的 AJAX 方法的 success 处理程序中,如下所示:

$.ajax({
   //options
   success: function(data) {
     $('textarea.blog_comment').autoresize({...plugin options...});
   }
});

或者使用类似 .livequery(),如下所示:

$('textarea.blog_comment').livequery(function() {
  $(this).autoResize({
    onResize : function() {
      $(this).css({opacity:0.8});
    },
    animateCallback : function() {
      $(this).css({opacity:1});
    },
    animateDuration : 300,
    extraSpace : 40
  });
});

简短的版本是 .live() 对此不起作用......它是事件驱动的,所以不太适合运行大多数插件。

You either need to re-run the plugin after your elements are ready again, e.g. in the success handler of whichever AJAX method you're using, like this:

$.ajax({
   //options
   success: function(data) {
     $('textarea.blog_comment').autoresize({...plugin options...});
   }
});

Or use a plugin like .livequery(), like this:

$('textarea.blog_comment').livequery(function() {
  $(this).autoResize({
    onResize : function() {
      $(this).css({opacity:0.8});
    },
    animateCallback : function() {
      $(this).css({opacity:1});
    },
    animateDuration : 300,
    extraSpace : 40
  });
});

The short version is that .live() doesn't work for this...it's event driven, so not really suited for running most plugins.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文