-
Notifications
You must be signed in to change notification settings - Fork 2
/
autoscroll.min.js
1 lines (1 loc) · 1.97 KB
/
autoscroll.min.js
1
!function(){function a(a){this.scrollObj=null,a=a||{},this.scrollId=a.scrollId,this.scrollIdx=a.scrollIndex||0,this.time=a.speed||40,this.stopable=a.stopable,this.scrollCache=null,this.stopCache=null,this.init()}a.prototype={consturctor:a,init:function(){this.scrollObj=document.getElementById(this.scrollId),this.addScrollAction()},getFixHeight:function(){var a=this.scrollObj.clientHeight;return a>380?380:a},addScrollAction:function(){var c,d,a=this,b=this.scrollObj.parentNode;b.style.height=this.getFixHeight()+"px",b.style.overflow="hidden",c=a.cloneAndAppendParent(this.scrollObj,b),a.stopable&&a.stopToView(),d=setTimeout(function(){a.toScroll()},a.time),a.scrollCache={obj:this.scrollObj,clone:c,timer:d}},cloneAndAppendParent:function(a,b){var c=a.cloneNode(!0);return b.appendChild(c),c},scrollToOrback:function(a){a.clone.offsetHeight-a.obj.parentNode.scrollTop<=0?a.obj.parentNode.scrollTop=0:a.obj.parentNode.scrollTop++},toScroll:function(){var a=this,b=a.scrollCache;clearTimeout(b.timer),this.watchStopCahche()||(this.scrollToOrback(b),b.timer=setTimeout(function(){a.toScroll()},a.time))},watchStopCahche:function(){return null!==this.stopCache?!0:!1},stopToView:function(){var a=this.scrollObj.parentNode;this.bindFn(a,"mouseover",function(a){var b=a?a.currentTarget.children[this.scrollIdx]:event.srcElement.parentNode.parentNode;null===this.stopCache&&(this.stopCache={obj:b})}),this.bindFn(a,"mouseout",function(a){var b=a?a.currentTarget.children[this.scrollIdx]:event.srcElement.parentNode.parentNode,c=this;this.stopCache.obj===b&&(this.stopCache.timer=setTimeout(function(){c.toScroll()},this.time),this.stopCache.clone=this.nextElement(b),this.scrollCache=this.stopCache,this.stopCache=null)})},nextElement:function(a){return a.nextSibling.nextSibling},bindFn:function(a,b,c){window.addEventListener?a.addEventListener(b,c.bind(this),!1):window.attachEvent&&a.attachEvent("on"+b,c.bind(this))}},"undefined"!=typeof module&&"object"==typeof module.exports?module.exports=a:window.Autoscroll=a}();