(function($) { jQuery.fn.progressBar = function( options ) { //Default values for progress_bar var defaults = { height : "30", backgroundColor : "#E0E0E0", barColor : "#F97352", targetBarColor : "#CCC", percentage : true, shadow : false, border : false, animation : false, animateTarget : false, }; var settings = $.extend( {}, defaults, options ); return this.each( function() { var elem = $( this ); $.fn.replaceProgressBar( elem, settings ); }); }; $.fn.replaceProgressBar = function( item, settings ) { var skill = item.text(); var progress = item.data( 'width' ); var target = item.data ( 'target' ); var bar_classes = ' '; var animation_class = ''; var bar_styles = 'background-color:' + settings.backgroundColor + ';height:' + settings.height + 'px;'; if ( settings.shadow ) { bar_classes += 'shadow'; } if ( settings.border ) { bar_classes += ' border'; } if ( settings.animation ) { animation_class = ' animate'; } var overlay = '
'; overlay += '

' + skill + '

'; overlay += '
'; // Render the progress bar background overlay += ''; // Display target bar only if set if ( target ) { if ( settings.animateTarget ) { overlay += ''; } else { overlay += ''; } } // Render the progress bar if ( settings.animation ) { overlay += ''; } else { overlay += ''; } // Render the percentage if enabled if ( settings.percentage ) { overlay += '' + progress + '%'; } // End overlay += '
'; // Render the progress bar on the page $( item ).replaceWith( overlay ); }; var animate = function() { var doc_height = $(window).height(); $( '.sonny_progressbar.animate' ).each( function() { var position = $( this ).offset().top; if ( ( $(window).scrollTop() + doc_height - 60 ) > position ) { var progress = $( this ).data( 'width' ) + "%"; $( this ).removeClass( 'animate' ); $( this ).find( '.bar' ).css('opacity', '0.1'); $( this ).find( '.bar' ).animate({ width : progress, opacity : 1 }, 3000 ); } }); }; // Looking for an animation element in the view $(window).scroll(function() { if ( $( '.sonny_progressbar.animate' ).length < 1 ) { return; } // If there is an animate element visible on the page, trigger the animation animate(); }); })(jQuery);