itzsoprokilla
New Member
I'm trying to get a page to use autoscrolling with a progressive log. Can someone help me with the current code. Synopsis: If the scroller is at the bottom then autoscroll if not then no autoscroll\[code\]<script type="text/javascript">var scroller = new AutoScroller(document.body);$(document).ready(function(){ var autoScroll = true; var initialLoad = true; var stickToBottom = scroller.isSticking(); setInterval(ajaxAll, 1000); function ajaxAll() { $.ajax ({ url: "/views/log/getLog", cache: false, success: function(data) {$('#ajaxLog').html(data);} }); if(stickToBottom) { scroller.scrollToBottom(); } }function AutoScroller(scrollContainer) { // get the height of the viewport. function getViewportHeight() { if (typeof(window.innerWidth ) == 'number') { //Non-IE return window.innerHeight; } else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )) { //IE 6+ in 'standards compliant mode' return document.documentElement.clientHeight; } else if (document.body && ( document.body.clientWidth || document.body.clientHeight )) { //IE 4 compatible return document.body.clientHeight; } return null; } return { bottomThreshold : 25, scrollContainer: scrollContainer, getCurrentHeight : function() { var scrollDiv = $(this.scrollContainer); if (scrollDiv.scrollHeight > 0) return scrollDiv.scrollHeight; else if (objDiv.offsetHeight > 0) return scrollDiv.offsetHeight; return null; // huh? }, // return true if we are in the "stick to bottom" mode isSticking : function() { var scrollDiv = $(this.scrollContainer); var currentHeight = this.getCurrentHeight(); // when used with the BODY tag, the height needs to be the viewport height, instead of // the element height. //var height = ((scrollDiv.style.pixelHeight) ? scrollDiv.style.pixelHeight : scrollDiv.offsetHeight); var height = getViewportHeight(); var diff = currentHeight - scrollDiv.scrollTop - height; // window.alert("currentHeight=" + currentHeight + ",scrollTop=" + scrollDiv.scrollTop + ",height=" + height); return diff < this.bottomThreshold; }, scrollToBottom : function() { var scrollDiv = $(this.scrollContainer); scrollDiv.scrollTop = this.getCurrentHeight(); } };}});</script>\[/code\]