<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/**
 * @author ares
 */

(function(window){
	var AresMouseWheel = function(){
		var _handler;
		var _self = this;

		function add(target, handler){
			if(target.addEventListener){
				target.addEventListener('DOMMouseScroll', wheel, false);
			}
			if(target == window){
				if(window.onmousewheel == undefined){
					document.onmousewheel = wheel;
				}else{
					window.onmousewheel = wheel;
				}
			}else{
				target.onmousewheel = wheel;
			}
			_handler = handler;
		}
		function remove(target){
			if(target.removeEventListener){
				target.removeEventListener('DOMMouseScroll', wheel, false);
			}
			if(target == window){
				if(window.onmousewheel == undefined){
					document.onmousewheel = null;
				}else{
					window.onmousewheel = null;
				}
			}else{
				target.onmousewheel = null;
			}
		}
		function wheel(e){
			var delta;
			if(!e){
				e = window.event;
			}
			if(e.wheelDelta){
				delta = e.wheelDelta/120;
			}else if(e.detail){
				delta = -e.detail/3;
			}
			if(e.preventDefault)
                e.preventDefault();
			e.returnValue = false;
			_handler.call(_self, delta);
		}
		this.add = function(target, handler){
			add(target, handler);
		};
		this.remove = function(target){
			remove(target);
		};
	};

	var AresAnimateScroll = function(option){
		var $navigator = option.navigatorList;
		var $content = option.contentList;
		var _event = option.event || {};
		var _useWheel = option.useWheel || false;
		var _useKeyboard = option.useKeyboard || false;
		var _isAnimate = false;

		init();

		function init(){
			$navigator.on('click', function(e){
				var scrollTop = $($(this).attr('href')).offset().top;
				animateScroll(scrollTop);
				return false;
			});

			$(window).on('scroll', scrollHandler).trigger('scroll');
			if(_useWheel){
				var wheel = new AresMouseWheel();
				wheel.add(window, wheelHandler);
			}
			if(_useKeyboard){
				$(window).on('keydown', keyHandler);
			}
		}

		function scrollHandler(e){
			if(_event.update) _event.update();
			activeNavigator($(this).scrollTop());
		}

		function keyHandler(e){
			var keyCode = e.keyCode;
			if(keyCode == 40){
				nextPage();
			}else if(keyCode == 38){
				prevPage();
			}
			return false;
		}

		function wheelHandler(delta){
			if(_isAnimate) return;
			var scrollTop;

			if(delta &lt; 0){
				nextPage();
			}else{
				prevPage();
			}
		}

		function nextPage(){
			var activeIndex = getActiveIndex();
			if(activeIndex == $content.size()-1) return;
			scrollTop = $content.eq(activeIndex+1).offset().top;
			animateScroll(scrollTop);
		}
		function prevPage(){
			var activeIndex = getActiveIndex();
			if(activeIndex == 0) return;
			scrollTop = $content.eq(activeIndex-1).offset().top;
			animateScroll(scrollTop);
		}

		function activeNavigator(scrollTop){
			var distArray = [];
			for(var i=0; i&lt;$navigator.size(); i++){
				// var offsetTop = parseInt($($navigator.eq(i).attr('href')).offset().top);
				// var dist = Math.abs(offsetTop-scrollTop);
				// distArray[i] = {dist:dist, navEl:$navigator.eq(i), conEl:$($navigator.eq(i).attr('href'))};
			}
			distArray.sort(function(a, b){
				return a.dist &lt; b.dist ? -1 : a.dist &gt; b.dist ? 1 : 0;
			});
			for(i=0; i&lt;distArray.length; i++){
				if(i==0){
					distArray[i].navEl.addClass('active');
					distArray[i].conEl.addClass('active');
				}else{
					distArray[i].navEl.removeClass('active');
					distArray[i].conEl.removeClass('active');
				}
			}
		}

		function animateScroll(scrollTop){
			if(_isAnimate) return;
			if(_event.start) _event.start();
			_isAnimate = true;
			var scrollBottom = document.getElementsByTagName('body')[0].scrollHeight - $(window).height();
			if(scrollTop &gt; scrollBottom) scrollTop = scrollBottom;
			$('html, body').stop().animate({scrollTop:scrollTop}, {duration:500, complete:function(){
				if(_event.end &amp;&amp; !_isAnimate) _event.end();
				_isAnimate = false;

			}});
		}

		function getActiveIndex(){
			for(var i=0; i&lt;$content.size(); i++){
				if($content.eq(i).hasClass('active')) return i;
			}
			return -1;
		}

		this.animateScroll = function(scrollTop){
			animateScroll(scrollTop);
		};

		this.getActiveIndex = function(){
			return getActiveIndex();
		};
	};
	window.AresAnimateScroll = AresAnimateScroll;
})(window);
</pre></body></html>