-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rssscroll.js
executable file
·1 lines (1 loc) · 2.07 KB
/
Rssscroll.js
1
function iScrollRss(el){this.element = el;this.position = 0;this.refresh();this.element.style.webkitTransitionTimingFunction = 'cubic-bezier(0, 0, 0.2, 1)';this.acceleration = 0.009;this.element.addEventListener('touchstart', this, false);}iScrollRss.prototype = {handleEvent: function(e) {switch(e.type) {case 'touchstart': this.onTouchStart(e); break;case 'touchmove': this.onTouchMove(e); break;case 'touchend': this.onTouchEnd(e); break;case 'webkitTransitionEnd': this.onTransitionEnd(e); break;}}, get position() {return this._position;},set position(pos) { this._position = pos;this.element.style.webkitTransform = 'translate3d(0, ' + this._position + 'px, 0)';},refresh: function() { this.element.style.webkitTransitionDuration = '0';if( this.element.offsetWidth<this.element.parentNode.clientWidth )this.maxScroll = 0; else this.maxScroll = this.element.parentNode.clientWidth - this.element.offsetWidth;}, onTouchStart: function(e) { e.preventDefault(); this.element.style.webkitTransitionDuration = '0';var theTransform = window.getComputedStyle(this.element).webkitTransform;theTransform = new WebKitCSSMatrix(theTransform).m42;this.startX = e.targetTouches[0].clientX;this.scrollstartX = this.position; this.scrollStartTime = e.timeStamp; this.moved = false; this.element.addEventListener('touchmove', this, false);this.element.addEventListener('touchend', this, false);return false;},onTouchMove: function(e) {if( e.targetTouches.length != 1 )return false;this.endX = e.targetTouches[0].clientX;this.moved = true; return false;},onTouchEnd: function(e) {this.element.removeEventListener('touchmove', this, false); this.element.removeEventListener('touchend', this, false);var dir;if(this.startX-this.endX>0) dir='left';else dir='right';if( !this.moved ) { var theTarget = e.target;if(theTarget.nodeType == 3) theTarget = theTarget.parentNode;var theEvent = document.createEvent("MouseEvents");theEvent.initEvent('click', true, true);theTarget.dispatchEvent(theEvent); return false}this.scrollTo(dir);return false;},scrollTo: function(dir) {update();if(dir=='left') moverFeed();if(dir=='right') moverFeedR();}};