Javascript Course

The JavaScript function presented in this page can be used to Detect when ScrollBar reaches the bottom of the page.
This function is useful when you want to execute some JavaScript code when the user scrolls till the bottom of page, for example to display another content, making an infinite scroll.
Here is the function, named whenScrlBottom(). It must be accessed by the "onscroll" event.
// function to detect when scroollbar reaches the bottom of page
var whenScrlBottom = function() {
  // https://coursesweb.net/javascript/
  var win_h = (self.innerHeight) ? self.innerHeight : document.body.clientHeight;    // gets window height

  // gets current vertical scrollbar position
  var scrl_pos = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;

  // if scrollbar reaces to bottom
  if (document.body.scrollHeight <= (scrl_pos + win_h)) {
    alert('Bottom');
  }
}

// register event on scrollbar
window.onscroll = whenScrlBottom;

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which attribute is used in <img> tag for the address of the image?
href src rel
<img src="http://coursesweb.net/imgs/webcourses.gif" width="191" height="63" alt="Courses-Web" />
Which CSS code hides the element on page?
display: none; display: inline; position: relative;
#id {
  display: none;
}
What instruction stops the execution of a while() or for() statement?
continue prompt() break
for(var i = 0; i< 8; i++) {
  if(i > 1) break;
  alert(i);
}
Indicate the function that can create a constant.
define() include() defined()
define("CONSTANT_NAME", "value");
echo CONSTANT_NAME;
Detect when ScrollBar reaches the bottom of the page

Last accessed pages

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (135112)
  2. PuzzleImg - Script to Create Image Puzzle Game (9213)
  3. Refresh page if window width changes from a device size to other (1643)
  4. CSS Trapezoid Shape (11161)
  5. Check and Validate input field when loses focus, with PHP via Ajax (6696)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (443)
  2. SHA1 Encrypt data in JavaScript (234)
  3. PHP Unzipper - Extract Zip, Rar Archives (217)
  4. Read Excel file data in PHP - PhpExcelReader (216)
  5. Get and Modify content of an Iframe (139)