javascript - Use jQuery to scroll to display element which was loaded in via AJAX -


i have script gets images via ajax , displays them on page in div called #media-area, has fixed height , overflow: scroll;. this, user's can select image. on pages, image selected. in case want div scroll selected image positioned along top.

$.ajax({     url: 'index.php?c=media&m=media_ajax',     success: function (res) {         (var index in res) {             var me = res[index];              var html = '<div class="col-md-3"><input type="radio" name="medialibrary" id="medialibrary' + me.id + '" value="' + me.id + '">';             html += '<label for="medialibrary' + me.id + '">';             html += '<img src="/image.php?image=' + me.image + '&thumbnail=122,122" alt="' + me.name + '" id="img_medialibrary' + me.id + '" width="122" height="122">';             html += '</a>';             html += '</div>';              $("#media-area").append(html);              $("#medialibrary" + me.id).change(function () {                 window.selected = $(this).val();                 $("#ml_selected").val($(this).val());                 $("#clear-selection").removeattr('disabled');                 $("#upload").hide();             });              if ($("#ml_selected").val() == me.id) {                 $("#clear-selection").removeattr('disabled');                 $("#upload").hide();                 $("#medialibrary" + me.id).attr('checked', 'checked');             }         }          $('#media-area input').each(function () {             var radioinput = $(this);             if (radioinput.is(':checked')) {                 var radioimg = $("#img_" + radioinput.attr('id'));                 $('#media-area').animate({                     scrolltop: radioimg.offset().top                 }, 2000);              }         });      } }); 

i can div scroll, won't anywhere near selected div. i'm guessing because images haven't loaded when scroll event fired. how go running event scroll selected item after images have been loaded in via ajax?


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -