开发者

jquery + autoresize re-bind on ajax loaded divs

开发者 https://www.devze.com 2023-03-17 00:16 出处:网络
I use the following module to do auto-scaling on my textareas http://james.padolsey.com/javascript/jquery-plugin-autoresize/

I use the following module to do auto-scaling on my textareas

http://james.padolsey.com/javascript/jquery-plugin-autoresize/

It works great till I load some new textareas via ajax. I'm use to just switching .click with .live('click', fn) and it works fine.. but not this time.

My js to init auto-resize looks like

$('textarea.comment_entry').autoResize({
    onResize : function() {
        $(this).css({opacity:0.8});
    },
    animateCallback : function() {
        $(this).css({opacity:1});
   开发者_运维技巧 },
    animateDuration : 300,
    extraSpace : 10
});

I was using the infinite scroll plugin and this was the magic

$('div#content').infinitescroll({

  navSelector  : "a#next:last",            
  nextSelector : "a#next:last",   
  itemSelector : "#content div.content_box",
  donetext     : ""
},function(posts){
    $('textarea.comment_entry').autoResize({
        onResize : function() {
            $(this).css({opacity:0.8});
        },
        animateCallback : function() {
            $(this).css({opacity:1});
        },
        animateDuration : 300,
        extraSpace : 10
    });
});


Can you add the plugin to the new textareas on the success:function() of the ajax response?

0

精彩评论

暂无评论...
验证码 换一张
取 消