Template:Team:NCTU Formosa/js/verysmoothy

From 2013.igem.org

/**

* jquery.simplr.smoothscroll
* version 1.0
* copyright (c) 2012 https://github.com/simov/simplr-smoothscroll
* licensed under MIT
* requires jquery.mousewheel - https://github.com/brandonaaron/jquery-mousewheel/
*/
(function($) {
   'use strict';
   
   $.srSmoothscroll = function(options) {
   
   var self = $.extend({
       step: 55,
       speed: 400
   }, options || {});
   
   // private fields & init
   var win = $(window),
       doc = $(document),
       top = 0,
       step = self.step,
       speed = self.speed,
       viewport = win.height(),
       body = $.browser.webkit ? $('body') : $('html'),
       wheel = false;
   // events
   $('body').mousewheel(function(event, delta) {
       wheel = true;
       if (delta < 0) // down
           top = (top+viewport) >= doc.height() ? top : top+=step;
       else // up
           top = top <= 0 ? 0 : top-=step;
       body.stop().animate({scrollTop: top}, speed, function () {
           wheel = false;
       });
       return false;
   });
   win
   .on('resize', function (e) {
       viewport = win.height();
   })
   .on('scroll', function (e) {
       if (!wheel)
           top = win.scrollTop();
   });
   
   };

})(jQuery);