Permalink
Browse files

adding files

  • Loading branch information...
0 parents commit 820715f0d906af826433e35f6847bcc380c347a8 Michael Lynch committed Aug 21, 2014
Showing with 572 additions and 0 deletions.
  1. +37 −0 .gitignore
  2. +21 −0 LICENSE.md
  3. +52 −0 README.md
  4. +12 −0 build/scrollgress.min.js
  5. +162 −0 demo/index.html
  6. +166 −0 demo/overflow.html
  7. +30 −0 src/css/styles.css
  8. BIN src/img/grumpy.jpg
  9. BIN src/img/picard.jpg
  10. +92 −0 src/scrollgress.js
@@ -0,0 +1,37 @@
+# Compiled source #
+###################
+*.com
+*.class
+*.dll
+*.exe
+*.o
+*.so
+
+# Packages #
+############
+# it's better to unpack these files and commit the raw source
+# git has its own built in compression methods
+*.7z
+*.dmg
+*.gz
+*.iso
+*.jar
+*.rar
+*.tar
+*.zip
+
+# Logs and databases #
+######################
+*.log
+*.sql
+*.sqlite
+
+# OS generated files #
+######################
+.DS_Store
+.DS_Store?
+._*
+.Spotlight-V100
+.Trashes
+ehthumbs.db
+Thumbs.db
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2014 Michael Lynch
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,52 @@
+#Scrollgress
+
+Inspired by [Pitchfork](http://pitchfork.com/features/staff-lists/9466-the-top-200-tracks-of-2010-2014/), Scrollgress is a simple, lightweight jQuery plugin used to display a progress bar at the top of the page that fills up as the user scrolls. Progress can be measured as the user scrolls the page or an element that has `overflow: scroll | auto` or `overflow-y: scroll | auto`.
+
+<a href="http://michael-lynch.github.io/scrollgress/" target="_blank">See a demo</a>
+
+<a href="http://michael-lynch.github.io/scrollgress/overflow.html" target="_blank">See a demo using an overflow element</a>
+
+##Instructions
+
+Include jQuery and the plugin in the head or footer of your page.
+
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
+
+ <script src="/js/plugins/scrollgress.js"></script>
+
+Initialize the plugin targeting the class, ID or element that you want to display the scroll progress of.
+
+ $('body').scrollgress();
+
+####Options
+
+<ol>
+
+<li>
+height: "Npx"
+<br />A string that defines the height of the progress bar in pixels (default: '5px').
+</li>
+
+<li>color: color
+<br />A string that defines the color of the progress bar (default: '#ff0000').
+</li>
+
+<li>success: function()
+<br />A callback function that runs after scrollgress has been initiated (default: function()).
+</li>
+
+</ol>
+
+#####Example:
+
+ $(function() {
+
+ $('.post').scrollgress({
+ height: 10px,
+ color: #990000,
+ success: function() {
+ console.log('Scrollgress has been initiated.');
+ }
+ });
+
+ });
@@ -0,0 +1,12 @@
+/*!
+
+Name: Scrollgress
+Dependencies: jQuery
+Author: Michael Lynch
+Author URL: http://michaelynch.com
+Date Created: August 20, 2014
+Last Updated: August 20, 2014
+Licensed under the MIT license
+
+*/
+!function(s){s.fn.scrollgress=function(o){if(!this.length)return this;var t={height:"5px",color:"#ff0000",success:function(){}},r=this;r.settings={},r.settings=s.extend({},t,o);var e=r.settings,i=s(this),l=i.css("overflow"),c=i.css("overflow-y"),g="auto"===l||"scroll"===l||"auto"===c||"scroll"===c?!0:!1,n=s(window).outerHeight(),h=g?i[0].scrollHeight:i.height(),d=g?i:s(window),a='<div class="scrollgress"><div class="scrollgress__progress"></div></div>';s("body").prepend(a),s(".scrollgress").css({position:"fixed",top:"0px",left:"0px",background:"transparent",width:"100%",height:e.height}),s(".scrollgress__progress").css({"float":"left",background:e.color,width:"0%",height:e.height}),d.scroll(function(o){var t=g?i.scrollTop():o.originalEvent.pageY,r=(t/(h-n)*100).toFixed(2);s(".scrollgress__progress").css({width:r+"%"})}),e.success.call(this)}}(jQuery);
Oops, something went wrong.
Oops, something went wrong.
@@ -0,0 +1,30 @@
+body {
+ font: 18px Arial, Helvetica, sans-serif;
+ line-height: 28px;
+ margin: 0;
+}
+
+.wrapper {
+ box-sizing: border-box;
+ background: #eee;
+ margin: 40px auto;
+ height: 10000px;
+ width: 90%;
+ max-width: 800px;
+ padding: 30px;
+}
+
+.wrapper.wrapper--overflow {
+ height: 400px;
+ overflow-y: scroll;
+}
+
+h1 {
+ margin: 0 0 20px 0;
+}
+
+.wrapper img {
+ margin: 0 0 15px 0;
+ width: 100%;
+ height: auto;
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,92 @@
+/*!
+
+Name: Scrollgress
+Dependencies: jQuery
+Author: Michael Lynch
+Author URL: http://michaelynch.com
+Date Created: August 20, 2014
+Last Updated: August 20, 2014
+Licensed under the MIT license
+
+*/
+
+;(function($) {
+
+ $.fn.scrollgress = function(options) {
+
+ //return if no element was bound
+ //so chained events can continue
+ if(!this.length) {
+ return this;
+ }
+
+ //define default parameters
+ var defaults = {
+ height: '5px',
+ color: '#ff0000',
+ success: function() {}
+ }
+
+ //define plugin
+ var plugin = this;
+
+ //define settings
+ plugin.settings = {}
+
+ //merge defaults and options
+ plugin.settings = $.extend({}, defaults, options);
+
+ var s = plugin.settings;
+
+ //define element
+ var el = $(this);
+
+ var elOverflow = el.css('overflow');
+ var elOverflowY = el.css('overflow-y');
+
+ var hasOverflow = (elOverflow === 'auto' || elOverflow === 'scroll' || elOverflowY === 'auto' || elOverflowY === 'scroll') ? true : false;
+
+ var windowHeight = $(window).outerHeight();
+
+ var heightToScroll = (hasOverflow) ? el[0].scrollHeight : el.height();
+
+ var elementToScroll = (hasOverflow) ? el : $(window);
+
+ var progressBar = '<div class="scrollgress"><div class="scrollgress__progress"></div></div>';
+
+ $('body').prepend(progressBar);
+
+ $('.scrollgress').css({
+ position: 'fixed',
+ top: '0px',
+ left: '0px',
+ background: 'transparent',
+ width: '100%',
+ height: s.height
+ });
+
+ $('.scrollgress__progress').css({
+ float: 'left',
+ background: s.color,
+ width: '0%',
+ height: s.height
+ });
+
+ elementToScroll.scroll(function(e) {
+
+ var amountScrolled = (hasOverflow) ? el.scrollTop() : e.originalEvent.pageY;
+
+ // divide the amount of pixels scrolled by the total height to scroll minus the height of the window
+ // and round the result to two decimal places
+ var percentScrolled = ((amountScrolled / (heightToScroll - windowHeight)) * 100).toFixed(2);
+
+ $('.scrollgress__progress').css({
+ width: percentScrolled + '%'
+ });
+ });
+
+ s.success.call(this);
+
+ }
+
+})(jQuery);

0 comments on commit 820715f

Please sign in to comment.