Permalink
Browse files

- fixed amountscrolled var for webkit browsers

  • Loading branch information...
1 parent 0b8724b commit 76a66b620c1d6d30d813f096012cf8bc53cc2f71 Michael Lynch committed Jun 19, 2015
Showing with 5 additions and 3 deletions.
  1. +2 −2 build/scrollgress.min.js
  2. +3 −1 src/scrollgress.js
@@ -5,8 +5,8 @@ Dependencies: jQuery
Author: Michael Lynch
Author URL: http://michaelynch.com
Date Created: August 20, 2014
-Last Updated: August 20, 2014
+Last Updated: June 19, 2015
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);
+!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,l=s(this),i=l.css("overflow"),c=l.css("overflow-y"),n="auto"===i||"scroll"===i||"auto"===c||"scroll"===c?!0:!1,g=s(window).outerHeight(),h=n?l[0].scrollHeight:l.height(),d=n?l: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=n?l.scrollTop():s(document).scrollTop(),r=(t/(h-g)*100).toFixed(2);console.log(o.originalEvent),s(".scrollgress__progress").css({width:r+"%"})}),e.success.call(this)}}(jQuery);
View
@@ -74,12 +74,14 @@ Licensed under the MIT license
elementToScroll.scroll(function(e) {
- var amountScrolled = (hasOverflow) ? el.scrollTop() : e.originalEvent.pageY;
+ var amountScrolled = (hasOverflow) ? el.scrollTop() : $(document).scrollTop();
// 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);
+ console.log(e.originalEvent);
+
$('.scrollgress__progress').css({
width: percentScrolled + '%'
});

0 comments on commit 76a66b6

Please sign in to comment.