jQuery scrollTop函数在ajax调用后不工作 [英] jQuery scrollTop function not working after ajax call
本文介绍了jQuery scrollTop函数在ajax调用后不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是我的ajax调用...工作正常,但scrollTo插件从Jquery不是定位的内容,我想要的是。
here is my ajax call... works fine but the scrollTo plugin from Jquery is not positioning the content where I want it to be. below
//this will show the contents of the email body when the list item is clicked.
jQuery("#list-item-"+username+"").click(function(){
jQuery(".reply-to-container").hide();
jQuery("#reply-to-"+username+"").toggle("slide", {direction: 'up'});
jQuery("#reply-input-"+username+"").val('');
jQuery(".display-reply-content").html("");
jQuery("#send-btn-ajax-"+username+"").hide();
jQuery("#reply-input-"+username+"").hide("slide", {direction: 'up'});
var myUsername = getUrlVars()['username'];
var messageID = <?php echo $this->message_id; ?>;
var dataString = 'messageID='+ messageID + '&friend=' + username + '&myUsername=' + myUsername;
$.ajax({
type: "POST",
url: "/friends/mark-read/",
data: dataString,
cache: false,
success: function(html)
{
jQuery("#mail-icon-"+username+"").replaceWith("<div id='mail-icon-"+username+"' class='ui-icon ui-icon-mail-open mail-closed'>");
jQuery("#display-reply-"+username+"").css({"display" : "none"}).html(html).fadeIn(2500);
console.log(jQuery("#display-reply-"+username+"")[0].scrollHeight);
jQuery("#display-reply-"+username+"").scrollTop(jQuery("#display-reply-"+username+"").scrollHeight);
},
error: function(jqXHR, textStatus, errorThrown)
{
console.log(textStatus, errorThrown);
}
})
})
of the Div
Here is my CSS of the Div
.display-reply-content{
max-height: 200px;
overflow: auto;
}
推荐答案
jQuery("#display-reply-"+username+"").css({"display" : "none"}).html(html).fadeIn(1500, function() {
jQuery("#display-reply-"+username+"").scrollTop(jQuery("#display-reply-"+username+"")[0].scrollHeight);
});
这篇关于jQuery scrollTop函数在ajax调用后不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文