---
title: "scriptaculous 库的x轴移动"
author: "kc_ren"
date: "2009-05-06T19:14:16Z"
tags: []
slug: "scriptaculous-x"
draft: false
lastmod: "2009-05-06T19:17:54Z"
id: 380335
url: "https://i5tt.iteye.com/blog/380335"
---

最近开发需要 下载使用了 scriptaculous.js 

发现滚动条只有 Y 轴方向的定位移动

自己补充了 X 轴方向的移动定位

增加了接口 ScrollToX 

用法:　new Effect.ScrollToX(Obj)

```javascript

/*---------------------------
 * Title:scrollToX
 * Version: scriptaculous 1.5
 * Using: Prototype 1.4
 * Author:i5tt.com
 * Date: 2006-08-08
 * Web: www.i5tt.com
 *---------------------------*/

Effect.ScrollToX = Class.create();
Object.extend(Object.extend(Effect.ScrollToX.prototype, Effect.Base.prototype), {
 initialize: function(element) {
 this.element = $(element);
 this.start(arguments[1] || {});
 },
 setup: function() {
 Position.prepare();
 var offsets = Position.cumulativeOffset(this.element);
 if(this.options.offset) offsets[0] += this.options.offset;
 var max = window.innerWidth ? 
 window.width - window.innerWidth :
 document.body.scrollWidth - 
 (document.documentElement.clientWidth ? 
 document.documentElement.clientWidth : document.body.clientWidth);
 this.scrollStart = Position.deltaX;
 this.delta = (offsets[0] > max ? max : offsets[0]) - this.scrollStart;
 },
 update: function(position) {
 Position.prepare();
 window.scrollTo( 
 this.scrollStart + (position*this.delta) ,Position.deltaY);
 }
});
```