JScrollpane在ajax之后不会工作

时间:2012-02-23 18:34:53

标签: jquery html ajax jquery-jscrollpane

所以在我在div上加载一些内容后,我想初始化jscrollpane,但它不起作用。这是我的代码。看看你们是否可以告诉我出了什么问题。

Ajax(jquery)

   $("#mision").click(function() {
        var id = this.id;
        $.ajax({
          url: template + "/acciones.php",
          type: "POST",
          data:  "id=" + id,

          complete: function() {

          },

          success: function(x) {
            $("#cargaContenido").html(x);
                $("#scrollpro").css({'height':(($(window).height())-361)+'px'});
        $('#scrollpro').jScrollPane({

        });

        $(window).resize(function(){
          $('#scrollpro').css({'height':(($(window).height())-301)+'px'});
          $('#scrollpro').jScrollPane({autoReinitialise: true});
         });
              $("#scrollpro").trigger('resize');

         },

          error: function() {
            //called when there is an error
          },
        });

    });

现在确实有效!

2 个答案:

答案 0 :(得分:2)

试试这个:

$("#mision").click(function() {
    var id = this.id;
    $.ajax({
      url: template + "/acciones.php",
      type: "POST",
      data:  "id=" + id,

      complete: function() {
        $('#cargaContenido').jScrollPane().fadeIn();
      },

      success: function(x) {
        $("#cargaContenido").html(x);

     },

      error: function() {
        //called when there is an error
      },
    });

});

答案 1 :(得分:0)

它可能与fadeIn动画有关。我不认为jScrollPane可以在动画时测量内容。至少这是我的猜测。

请改为尝试:

$("#cargaContenido").html(x).fadeIn(500, function() {
    //Callback when the fadeIn is complete
    $('#cargaContenido').jScrollPane();
});
相关问题