Skip to content

Instantly share code, notes, and snippets.

@lotsofcode
Created January 11, 2012 12:54
Show Gist options
  • Save lotsofcode/1594530 to your computer and use it in GitHub Desktop.
Save lotsofcode/1594530 to your computer and use it in GitHub Desktop.
jquery plugin: check if a scrollbar has been scrolled 50% of overall height
$.fn.scrollCheck = function(options) {
var has_read_textarea = false;
textarea = $(this);
textarea.scroll(function() {
if ((textarea.scrollTop() + textarea.height()) >= (textarea[0].scrollHeight/2)) {
has_read_textarea = true;
}
});
var textarea_timeout = window.setInterval(function() {
if (has_read_textarea !== false) {
window.clearTimeout(textarea_timeout);
if (options.doNext) {
options.doNext();
}
}
}, options.timeout || 10000);
};
$("#test").scrollCheck({
timeout: 100,
doNext: function() {
$('#continue').show();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment