User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,501 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,671 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1131 | Replies: 1
Reply
Join Date: Sep 2007
Posts: 9
Reputation: bdichiara is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bdichiara bdichiara is offline Offline
Newbie Poster

Conditional Scroller

  #1  
Sep 19th, 2007
I am having the hardest time trying to write a condition for scrolling in an AJAX chat app i'm writing. After the AJAX request that updates the log, i'm using
objDiv.scrollTop = objDiv.scrollHeight;
I was trying to write a condition so if the user decides to scroll up to read older text, that it will not scroll them to the bottom until they are finished and scroll back down themselves. When doing this, i ran into a couple of issues. So, here's what I'm looking to do:
1. when the chat is initialized, i want it to perform the scroll function (above). It's possible that there already be messages in the window, so start them at the bottom.
2. if they are within 20px (or 30) from the bottom, then scroll them on down the rest of the way

There may be a better way to do this, if anyone has any suggestions. Otherwise i guess a series of conditions will help it behave normally.

Thanks.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 9
Reputation: bdichiara is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bdichiara bdichiara is offline Offline
Newbie Poster

Re: Conditional Scroller

  #2  
Sep 19th, 2007
Ok, i think i got this figured out:
var initialized = false;

... then inside the function ...

var objDiv = document.getElementById("message_window");
var sHeight = objDiv.scrollHeight;
var sTop = objDiv.scrollTop;
var mHeight = objDiv.clientHeight;
if(initialized){
	if((sTop+mHeight) >= (sHeight-30) && (sHeight > (mHeight+25))){
		objDiv.scrollTop = objDiv.scrollHeight;
	}
} else {
	var theDiv = document.getElementById("message_window");
	theDiv.scrollTop = theDiv.scrollHeight;
	initialized = true;
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC