-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78b2b6a
commit 669f0ad
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*! | ||
* Readingbar jQuery plugin | ||
* | ||
* @author : http://twitter.com/nicovanzyl | ||
* @author : http://twitter.com/wixelhq | ||
* @url : https://github.com/Wixel/readingbar.git | ||
* @copyright: 2015 Wixel | ||
* @license : MIT license | ||
* @version : 1.0 | ||
*/ | ||
|
||
(function($) { | ||
$.fn.viewportOffset = function() { | ||
var offset = $(this).offset(); | ||
|
||
return { | ||
top: offset.top + $(window).scrollTop() | ||
}; | ||
}; | ||
$.fn.readingbar = function(options) { | ||
if ($('.read-bar').length) { | ||
|
||
}else{ | ||
$('<div class="read-bar"></div>').appendTo('body'); | ||
$('.read-bar').css({ | ||
position: 'fixed', | ||
bottom: '0', | ||
left: '0', | ||
width: '0', | ||
maxWidth: '100%', | ||
}); | ||
var defaults = { | ||
backgroundColor: '#E76E66', | ||
height: '5px', | ||
}; | ||
settings = $.extend({}, defaults, options); | ||
$('.read-bar').css({ | ||
height: settings.height, | ||
backgroundColor: settings.backgroundColor | ||
}); | ||
}; | ||
_ = $(this); | ||
|
||
var readHeight = _.outerHeight(); | ||
var startPoint = _.offset().top * 1.8; | ||
var currentPos = 0; | ||
|
||
$(document).on('scroll', function(){ | ||
currentPos = (_.viewportOffset().top - startPoint) / readHeight * 100; | ||
$('.read-bar').css('width', currentPos + '%'); | ||
}); | ||
}; | ||
}(jQuery)); |