Skip to content

Instantly share code, notes, and snippets.

@hugofabricio
Created November 24, 2016 02:49
Show Gist options
  • Save hugofabricio/4efbd953037a3b83b78583efc32d3f7c to your computer and use it in GitHub Desktop.
Save hugofabricio/4efbd953037a3b83b78583efc32d3f7c to your computer and use it in GitHub Desktop.
(function ($) {
$.fn.progressBar = function(){
return this.each(function() {
var bar = this,
bar_progress = $(bar).find('.loading');
$(window).scroll(function(){
if(scrolledIntoView(bar)){
var each_bar_width = bar_progress.attr('aria-valuenow');
bar_progress.width(each_bar_width + '%');
};
});
});
};
function scrolledIntoView( element ) {
var docViewTop = $(window).scrollTop(),
docViewBottom = docViewTop + $(window).height(),
elemTop = $(element).offset().top,
elemBottom = elemTop + $(element).height();
return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom) && (elemBottom <= docViewBottom) && (elemTop >= docViewTop));
};
}( jQuery ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment