Jump to content


Photo

Scrolling to the bottom of a field


  • Please log in to reply
2 replies to this topic

#1 gerkintrigg

gerkintrigg

    Book Publisher

  • Members
  • PipPipPip
  • 814 posts
  • LocationPlymouth, UK
  • Age:33

Posted 01 October 2013 - 12:29 PM

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
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books

#2 Irate

Irate

    Advanced Member

  • Members
  • PipPipPip
  • 358 posts
  • LocationHamburg, Germany
  • Age:17

Posted 01 October 2013 - 02:43 PM

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/
Quod placet mihi non placeat tibi. - What I think to be good must not always equal your perception of it.

I am not perfect. I try a lot with the code I provide and I don't guarantee for it to work as I have mostly no option to test it on my mobile phone. I do apologize for any inconvenience I caused, but if I do happen to have helped, liking my posts or marking them as to have solved or answered your question would be nice.

#3 gerkintrigg

gerkintrigg

    Book Publisher

  • Members
  • PipPipPip
  • 814 posts
  • LocationPlymouth, UK
  • Age:33

Posted 02 October 2013 - 03:08 AM

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.


Edited by gerkintrigg, 02 October 2013 - 03:09 AM.

Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com