不知道這是否合法,但我只是採取了dojox.fx.scroll代碼並添加了上述的'偏移'功能(我也需要它)。
我開始使用Chrome調試器抓取dojox.fx.scroll代碼,並將其粘貼到腳本文件夾中的新.js文件中。
我將'define'字符串中的名稱從dojox/fx/scroll更改爲dojox/fx/scrollMod。我還將.smoothScroll的引用更改爲.smoothScrollMod。
define("dojox/fx/scrollMod", ["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/fx",
"dojox/fx/_base", "dojox/fx/_core", "dojo/dom-geometry", "dojo/_base/sniff"],
function (_1, _2, _3, _4, _5, _6, _7) {
_1.experimental("dojox.fx.scroll");
var fx = _2.getObject("dojox.fx", true);
_4.smoothScrollMod = function (_8) {
if (!_8.target) {
_8.target = _6.position(_8.node);
}
var dx = 0; //RW Custom Offsets
var dy = 0; //RW Custom Offsets
if (_8.offset) {
dx = _8.offset.x;
dy = _8.offset.y;
}
var _9 = _2[(_7("ie") ? "isObject" : "isFunction")](_8["win"].scrollTo),
_a = { x: _8.target.x + dx, y: _8.target.y + dy };
if (!_9) {
var _b = _6.position(_8.win); _a.x -= _b.x; _a.y -= _b.y;
}
var _c = (_9) ? (function (_d) { _8.win.scrollTo(_d[0], _d[1]); }) : (function (_e) { _8.win.scrollLeft = _e[0]; _8.win.scrollTop = _e[1]; });
var _f = new _3.Animation(_2.mixin({ beforeBegin: function() {
if (this.curve) { delete this.curve; }
var _10 = _9 ? dojo._docScroll() : { x: _8.win.scrollLeft, y: _8.win.scrollTop };
_f.curve = new _5([_10.x, _10.y], [_10.x + _a.x, _10.y + _a.y]);
}, onAnimate: _c
}, _8));
return _f;
};
fx.smoothScrollMod = _4.smoothScrollMod; return _4.smoothScrollMod;
});
添加以下到_4.smoothScrollMod方法:
<script src="scripts/dojoScrollMod.js" type="text/javascript"></script>
最後把它叫做:
var dx = 0; //RW Custom Offsets
var dy = 0; //RW Custom Offsets
if (_8.offset) {
dx = _8.offset.x;
dy = _8.offset.y;
}
然後你在HTML文件中像一個正常的腳本引用此文件像這樣(像你通常會,但與偏移對象):
var sm = new dojox.fx.smoothScrollMod({
node: dojo.query("mySelector")[0],
win: window,
easing: dojo.fx.easing.quadInOut,
offset: { "x": 0, "y": -200},
duration: 800
}).play();
說明:我的用戶羣是XP上的100%IE7(不是我的想法)。 – Bitwize 2011-02-17 23:13:36