gerkintrigg Posted October 1, 2013 Share Posted October 1, 2013 I'm using Ajax to make this chat box: Http://www.ghostlypublishing.com/chat All I want to happen is to automatically scroll to the bottom of the field. What's the easiest way to achieve this? Neil Link to comment https://forums.phpfreaks.com/topic/282609-scrolling-to-the-bottom-of-a-field/ Share on other sites More sharing options...
Irate Posted October 1, 2013 Share Posted October 1, 2013 Use $(obj).animate( { scrollTop: $(elementToScrollTo).offset().top } , 500, "swing", function(whenComplete){});. Also check out the documentation at the jQuery site if you need to know more about it. http://api.jquery.com/animate/ Link to comment https://forums.phpfreaks.com/topic/282609-scrolling-to-the-bottom-of-a-field/#findComment-1452089 Share on other sites More sharing options...
gerkintrigg Posted October 2, 2013 Author Share Posted October 2, 2013 I've done this: function loadLog(){ var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20; $.ajax({ url: "log.html", cache: false, success: function(html){ $("#chatbox").html(html); //Insert chat log into the #chatbox div var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20; if(newscrollHeight > oldscrollHeight){ $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div } }, }); } It would appear that this SHOULD work... but it's not. Link to comment https://forums.phpfreaks.com/topic/282609-scrolling-to-the-bottom-of-a-field/#findComment-1452151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.