How to call this function using JavaScript?

I just work with basic javascripts. Today I found the following and scroll through the DIV layer when new data is added to the DIV. I could not figure out how to call the function . Is it used with the window.onload function? or any other. And where should I declare the name DIV?

The code follows.

 var chatscroll = new Object(); chatscroll.Pane = function(scrollContainerId) { this.bottomThreshold = 25; this.scrollContainerId = scrollContainerId; } chatscroll.Pane.prototype.activeScroll = function() { var scrollDiv = document.getElementById(this.scrollContainerId); var currentHeight = 0; if (scrollDiv.scrollHeight > 0) currentHeight = scrollDiv.scrollHeight; else if (objDiv.offsetHeight > 0) currentHeight = scrollDiv.offsetHeight; if (currentHeight - scrollDiv.scrollTop - ((scrollDiv.style.pixelHeight) ? scrollDiv.style.pixelHeight : scrollDiv.offsetHeight) < this.bottomThreshold) scrollDiv.scrollTop = currentHeight; scrollDiv = null; } 

Update 1:

 <script type="text/javascript"> var chatscroll = new Object(); var chatScrollPane = new chatscroll.Pane('div1'); chatScrollPane.activeScroll() chatscroll.Pane = function (scrollContainerId) { this.bottomThreshold = 25; this.scrollContainerId = scrollContainerId; } chatscroll.Pane.prototype.activeScroll = function () { var scrollDiv = document.getElementById(this.scrollContainerId); var currentHeight = 0; if (scrollDiv.scrollHeight > 0) currentHeight = scrollDiv.scrollHeight; else if (objDiv.offsetHeight > 0) currentHeight = scrollDiv.offsetHeight; if (currentHeight - scrollDiv.scrollTop - ((scrollDiv.style.pixelHeight) ? scrollDiv.style.pixelHeight : scrollDiv.offsetHeight) < this.bottomThreshold) scrollDiv.scrollTop = currentHeight; scrollDiv = null; } </script> 
+4
source share
1 answer

chatscroll.Pane intended to be used as a constructor. You would create an instance like this:

 new chatscroll.Pane('somescrollContainerId'); 

The return value becomes reusable if you assign it to a variable.

 var chatScrollPane = new chatscroll.Pane('somescrollContainerId'); 

The incoming scrollContainerId will be the identifier ( id ) of the DIV element in your HTML document with which you want to use this object.

You do not need to declare it in window.onload , but that will certainly not hurt. All the constructor does is create a new object, set the this value for this new object, create and configure the bottomThreshold and scrollContainerId , and then return this new object when the constructor completes.

Just make sure that you never call the activeScroll function until the document has been fully analyzed, as it really is included in your document to retrieve and manipulate the elements.

+5
source

Source: https://habr.com/ru/post/1385937/


All Articles