Element.scrollHeight
This property was seen when analysing the accordian technique.
Once again in researching a particular aspect of css or html coding I came accross an example that prompted me to think "I wondered how they did that?". In this case it was a scrolling box that you had to scroll fully to the bottom before you could agree that you had read it.
The MDN Example - The license agreement
The MDN Example
The code
The "notice" box and the "rules" are styled as below:
<style> #notice { display: inline-block; margin-bottom: 12px; border-radius: 5px; width: 600px; padding: 5px; border: 2px #7FDF55 solid; } #rules { width: 600px; height: 130px; padding: 5px; border: #2A9F00 solid 2px; border-radius: 5px; } </style>
The following function is called when the page is loaded:
script> function checkReading () { if (checkReading.read) { return; } checkReading.read = this.scrollHeight - this.scrollTop === this.clientHeight; document.registration.accept.disabled = document.getElementById("nextstep").disabled = !checkReading.read; checkReading.noticeBox.innerHTML = checkReading.read ? "Thank you." : "Please, scroll and read the following text."; } onload = function () { var oToBeRead = document.getElementById("rules"); checkReading.noticeBox = document.createElement("span"); document.registration.accept.checked = false; checkReading.noticeBox.id = "notice"; oToBeRead.parentNode.insertBefore(checkReading.noticeBox, oToBeRead); oToBeRead.parentNode.insertBefore(document.createElement("br"), oToBeRead); oToBeRead.onscroll = checkReading; checkReading.call(oToBeRead); } /script>
Enhancements
To confirm that a user has actually read the agreement, as opposed to just scrolling to the end, text is added that has to be entered for process to continue.