| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- define(function(require, exports, module) {
- "use strict";
- var Util = require('./util'),
- Base = require('./base'),
- Core = require('./core'),
- Animate = require('./animate');
- var transformOrigin = Util.prefixStyle("transformOrigin");
- /**
- * @constructor
- * @param {object} cfg config for scroll
- * @extends XScroll
- * @example
- * var xscroll = new OriginScroll({
- * renderTo:"#scroll"
- * });
- * xscroll.render();
- */
- function OriginScroll(cfg) {
- OriginScroll.superclass.constructor.call(this, cfg);
- }
- Util.extend(OriginScroll, Core, {
- init: function() {
- var self = this;
- OriginScroll.superclass.init.call(this);
- self.resetSize();
- },
- /**
- * get scroll top value
- * @memberof OriginScroll
- * @return {number} scrollTop
- */
- getScrollTop: function() {
- return this.renderTo.scrollTop;
- },
- /**
- * get scroll left value
- * @memberof OriginScroll
- * @return {number} scrollLeft
- */
- getScrollLeft: function() {
- return this.renderTo.scrollLeft;
- },
- /**
- * vertical scroll absolute to the destination
- * @memberof SimuScroll
- * @param scrollTop {number} scrollTop
- * @param duration {number} duration for animte
- * @param easing {string} easing functio for animate : ease-in | ease-in-out | ease | bezier(n,n,n,n)
- **/
- scrollTop: function(y, duration, easing, callback) {
- var self = this;
- var y = Math.round(y);
- if (self.userConfig.lockY) return;
- var duration = duration || 0;
- var easing = easing || "quadratic";
- var config = {
- css: {
- scrollTop: y
- },
- duration: duration,
- easing: easing,
- run: function(e) {
- //trigger scroll event
- self.trigger("scroll", {
- scrollTop: self.getScrollTop(),
- scrollLeft: self.getScrollLeft()
- });
- },
- useTransition: false, //scrollTop
- end: callback
- };
- self.__timers.y = self.__timers.y || new Animate(self.renderTo, config);
- //run
- self.__timers.y.stop();
- self.__timers.y.reset(config);
- self.__timers.y.run();
- },
- /**
- * horizontal scroll absolute to the destination
- * @memberof SimuScroll
- * @param scrollLeft {number} scrollLeft
- * @param duration {number} duration for animte
- * @param easing {string} easing functio for animate : ease-in | ease-in-out | ease | bezier(n,n,n,n)
- **/
- scrollLeft: function(x, duration, easing, callback) {
- var self = this;
- var x = Math.round(x);
- if (self.userConfig.lockX) return;
- var duration = duration || 0;
- var easing = easing || "quadratic";
- var config = {
- css: {
- scrollLeft: x
- },
- duration: duration,
- easing: easing,
- run: function(e) {
- //trigger scroll event
- self.trigger("scroll", {
- scrollTop: self.getScrollTop(),
- scrollLeft: self.getScrollLeft()
- });
- },
- useTransition: false, //scrollTop
- end: callback
- };
- self.__timers.x = self.__timers.x || new Animate(self.renderTo, config);
- //run
- self.__timers.x.stop();
- self.__timers.x.reset(config);
- self.__timers.x.run();
- },
- _bindEvt: function() {
- OriginScroll.superclass._bindEvt.call(this);
- var self = this;
- if (self.__isEvtBind) return;
- self.__isEvtBind = true;
- self.renderTo.addEventListener("scroll", function(e) {
- self.trigger("scroll", {
- type: "scroll",
- scrollTop: self.getScrollTop(),
- scrollLeft: self.getScrollLeft()
- })
- }, false)
- }
- });
- if (typeof module == 'object' && module.exports) {
- module.exports = OriginScroll;
- }
- /** ignored by jsdoc **/
- else {
- return OriginScroll;
- }
- });
|