1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <title>API: animation Scroll.js (YUI Library)
</title>
5 <link rel=
"stylesheet" type=
"text/css" href=
"assets/api.css">
9 <div id=
"doc3" class=
"yui-t2">
12 <h1>Yahoo! UI Library
</h1>
13 <h3>animation
<span class=
"subtitle">2.2.0</span></h3>
15 <a href=
"./index.html">Yahoo! UI Library
</a>
16 > <a href=
"./module_animation.html">animation
</a>
18 > Scroll.js (source view)
27 <div class=
"highlight" ><pre><span class=
"o">(
</span><span class=
"k">function
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
28 <span class=
"c">/**
</span>
29 <span class=
"c"> * Anim subclass for scrolling elements to a position defined by the
"scroll
"</span>
30 <span class=
"c"> * member of
"attributes
". All
"scroll
" members are arrays with x, y scroll positions.
</span>
31 <span class=
"c"> *
<p
>Usage:
<code
>var myAnim = new YAHOO.util.Scroll(el, { scroll: { to: [
0,
800] } },
1, YAHOO.util.Easing.easeOut);
</code
></p
></span>
32 <span class=
"c"> * @class Scroll
</span>
33 <span class=
"c"> * @namespace YAHOO.util
</span>
34 <span class=
"c"> * @requires YAHOO.util.Anim
</span>
35 <span class=
"c"> * @requires YAHOO.util.AnimMgr
</span>
36 <span class=
"c"> * @requires YAHOO.util.Easing
</span>
37 <span class=
"c"> * @requires YAHOO.util.Bezier
</span>
38 <span class=
"c"> * @requires YAHOO.util.Dom
</span>
39 <span class=
"c"> * @requires YAHOO.util.Event
</span>
40 <span class=
"c"> * @requires YAHOO.util.CustomEvent
</span>
41 <span class=
"c"> * @extends YAHOO.util.Anim
</span>
42 <span class=
"c"> * @constructor
</span>
43 <span class=
"c"> * @param {String or HTMLElement} el Reference to the element that will be animated
</span>
44 <span class=
"c"> * @param {Object} attributes The attribute(s) to be animated.
</span>
45 <span class=
"c"> * Each attribute is an object with at minimum a
"to
" or
"by
" member defined.
</span>
46 <span class=
"c"> * Additional optional members are
"from
" (defaults to current value),
"units
" (defaults to
"px
").
</span>
47 <span class=
"c"> * All attribute names use camelCase.
</span>
48 <span class=
"c"> * @param {Number} duration (optional, defaults to
1 second) Length of animation (frames or seconds), defaults to time-based
</span>
49 <span class=
"c"> * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method)
</span>
50 <span class=
"c"> */
</span>
51 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">Scroll
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">(
</span><span class=
"nx">el
</span><span class=
"o">,
</span> <span class=
"nx">attributes
</span><span class=
"o">,
</span> <span class=
"nx">duration
</span><span class=
"o">,
</span> <span class=
"nx">method
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
52 <span class=
"k">if
</span> <span class=
"o">(
</span><span class=
"nx">el
</span><span class=
"o">)
</span> <span class=
"o">{
</span> <span class=
"c">// dont break existing subclasses not using YAHOO.extend
</span>
53 <span class=
"c"></span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">Scroll
</span><span class=
"o">.
</span><span class=
"nx">superclass
</span><span class=
"o">.
</span><span class=
"nx">constructor
</span><span class=
"o">.
</span><span class=
"nx">call
</span><span class=
"o">(
</span><span class=
"k">this
</span><span class=
"o">,
</span> <span class=
"nx">el
</span><span class=
"o">,
</span> <span class=
"nx">attributes
</span><span class=
"o">,
</span> <span class=
"nx">duration
</span><span class=
"o">,
</span> <span class=
"nx">method
</span><span class=
"o">);
</span>
54 <span class=
"o">}
</span>
55 <span class=
"o">};
</span>
57 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">extend
</span><span class=
"o">(
</span><span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">Scroll
</span><span class=
"o">,
</span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">ColorAnim
</span><span class=
"o">);
</span>
59 <span class=
"c">// shorthand
</span>
60 <span class=
"c"></span> <span class=
"k">var
</span> <span class=
"nx">Y
</span> <span class=
"o">=
</span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">;
</span>
61 <span class=
"k">var
</span> <span class=
"nx">superclass
</span> <span class=
"o">=
</span> <span class=
"nx">Y
</span><span class=
"o">.
</span><span class=
"nx">Scroll
</span><span class=
"o">.
</span><span class=
"nx">superclass
</span><span class=
"o">;
</span>
62 <span class=
"k">var
</span> <span class=
"nx">proto
</span> <span class=
"o">=
</span> <span class=
"nx">Y
</span><span class=
"o">.
</span><span class=
"nx">Scroll
</span><span class=
"o">.
</span><span class=
"nx">prototype
</span><span class=
"o">;
</span>
64 <span class=
"nx">proto
</span><span class=
"o">.
</span><span class=
"nx">toString
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
65 <span class=
"k">var
</span> <span class=
"nx">el
</span> <span class=
"o">=
</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">getEl
</span><span class=
"o">();
</span>
66 <span class=
"k">var
</span> <span class=
"nx">id
</span> <span class=
"o">=
</span> <span class=
"nx">el
</span><span class=
"o">.
</span><span class=
"nx">id
</span> <span class=
"o">||
</span> <span class=
"nx">el
</span><span class=
"o">.
</span><span class=
"nx">tagName
</span><span class=
"o">;
</span>
67 <span class=
"k">return
</span> <span class=
"o">(
</span><span class=
"s2">"Scroll
"</span> <span class=
"o">+
</span> <span class=
"nx">id
</span><span class=
"o">);
</span>
68 <span class=
"o">};
</span>
70 <span class=
"nx">proto
</span><span class=
"o">.
</span><span class=
"nx">doMethod
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">(
</span><span class=
"nx">attr
</span><span class=
"o">,
</span> <span class=
"nx">start
</span><span class=
"o">,
</span> <span class=
"nx">end
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
71 <span class=
"k">var
</span> <span class=
"nx">val
</span> <span class=
"o">=
</span> <span class=
"kc">null
</span><span class=
"o">;
</span>
73 <span class=
"k">if
</span> <span class=
"o">(
</span><span class=
"nx">attr
</span> <span class=
"o">==
</span> <span class=
"s1">'scroll
'</span><span class=
"o">)
</span> <span class=
"o">{
</span>
74 <span class=
"nx">val
</span> <span class=
"o">=
</span> <span class=
"o">[
</span>
75 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">method
</span><span class=
"o">(
</span><span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">currentFrame
</span><span class=
"o">,
</span> <span class=
"nx">start
</span><span class=
"o">[
</span><span class=
"m">0</span><span class=
"o">],
</span> <span class=
"nx">end
</span><span class=
"o">[
</span><span class=
"m">0</span><span class=
"o">]
</span> <span class=
"o">-
</span> <span class=
"nx">start
</span><span class=
"o">[
</span><span class=
"m">0</span><span class=
"o">],
</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">totalFrames
</span><span class=
"o">),
</span>
76 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">method
</span><span class=
"o">(
</span><span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">currentFrame
</span><span class=
"o">,
</span> <span class=
"nx">start
</span><span class=
"o">[
</span><span class=
"m">1</span><span class=
"o">],
</span> <span class=
"nx">end
</span><span class=
"o">[
</span><span class=
"m">1</span><span class=
"o">]
</span> <span class=
"o">-
</span> <span class=
"nx">start
</span><span class=
"o">[
</span><span class=
"m">1</span><span class=
"o">],
</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">totalFrames
</span><span class=
"o">)
</span>
77 <span class=
"o">];
</span>
79 <span class=
"o">}
</span> <span class=
"k">else
</span> <span class=
"o">{
</span>
80 <span class=
"nx">val
</span> <span class=
"o">=
</span> <span class=
"nx">superclass
</span><span class=
"o">.
</span><span class=
"nx">doMethod
</span><span class=
"o">.
</span><span class=
"nx">call
</span><span class=
"o">(
</span><span class=
"k">this
</span><span class=
"o">,
</span> <span class=
"nx">attr
</span><span class=
"o">,
</span> <span class=
"nx">start
</span><span class=
"o">,
</span> <span class=
"nx">end
</span><span class=
"o">);
</span>
81 <span class=
"o">}
</span>
82 <span class=
"k">return
</span> <span class=
"nx">val
</span><span class=
"o">;
</span>
83 <span class=
"o">};
</span>
85 <span class=
"nx">proto
</span><span class=
"o">.
</span><span class=
"nx">getAttribute
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">(
</span><span class=
"nx">attr
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
86 <span class=
"k">var
</span> <span class=
"nx">val
</span> <span class=
"o">=
</span> <span class=
"kc">null
</span><span class=
"o">;
</span>
87 <span class=
"k">var
</span> <span class=
"nx">el
</span> <span class=
"o">=
</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">getEl
</span><span class=
"o">();
</span>
89 <span class=
"k">if
</span> <span class=
"o">(
</span><span class=
"nx">attr
</span> <span class=
"o">==
</span> <span class=
"s1">'scroll
'</span><span class=
"o">)
</span> <span class=
"o">{
</span>
90 <span class=
"nx">val
</span> <span class=
"o">=
</span> <span class=
"o">[
</span> <span class=
"nx">el
</span><span class=
"o">.
</span><span class=
"nx">scrollLeft
</span><span class=
"o">,
</span> <span class=
"nx">el
</span><span class=
"o">.
</span><span class=
"nx">scrollTop
</span> <span class=
"o">];
</span>
91 <span class=
"o">}
</span> <span class=
"k">else
</span> <span class=
"o">{
</span>
92 <span class=
"nx">val
</span> <span class=
"o">=
</span> <span class=
"nx">superclass
</span><span class=
"o">.
</span><span class=
"nx">getAttribute
</span><span class=
"o">.
</span><span class=
"nx">call
</span><span class=
"o">(
</span><span class=
"k">this
</span><span class=
"o">,
</span> <span class=
"nx">attr
</span><span class=
"o">);
</span>
93 <span class=
"o">}
</span>
95 <span class=
"k">return
</span> <span class=
"nx">val
</span><span class=
"o">;
</span>
96 <span class=
"o">};
</span>
98 <span class=
"nx">proto
</span><span class=
"o">.
</span><span class=
"nx">setAttribute
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">(
</span><span class=
"nx">attr
</span><span class=
"o">,
</span> <span class=
"nx">val
</span><span class=
"o">,
</span> <span class=
"nx">unit
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
99 <span class=
"k">var
</span> <span class=
"nx">el
</span> <span class=
"o">=
</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">getEl
</span><span class=
"o">();
</span>
101 <span class=
"k">if
</span> <span class=
"o">(
</span><span class=
"nx">attr
</span> <span class=
"o">==
</span> <span class=
"s1">'scroll
'</span><span class=
"o">)
</span> <span class=
"o">{
</span>
102 <span class=
"nx">el
</span><span class=
"o">.
</span><span class=
"nx">scrollLeft
</span> <span class=
"o">=
</span> <span class=
"nx">val
</span><span class=
"o">[
</span><span class=
"m">0</span><span class=
"o">];
</span>
103 <span class=
"nx">el
</span><span class=
"o">.
</span><span class=
"nx">scrollTop
</span> <span class=
"o">=
</span> <span class=
"nx">val
</span><span class=
"o">[
</span><span class=
"m">1</span><span class=
"o">];
</span>
104 <span class=
"o">}
</span> <span class=
"k">else
</span> <span class=
"o">{
</span>
105 <span class=
"nx">superclass
</span><span class=
"o">.
</span><span class=
"nx">setAttribute
</span><span class=
"o">.
</span><span class=
"nx">call
</span><span class=
"o">(
</span><span class=
"k">this
</span><span class=
"o">,
</span> <span class=
"nx">attr
</span><span class=
"o">,
</span> <span class=
"nx">val
</span><span class=
"o">,
</span> <span class=
"nx">unit
</span><span class=
"o">);
</span>
106 <span class=
"o">}
</span>
107 <span class=
"o">};
</span>
108 <span class=
"o">})();
</span>
120 <li class=
"selected"><a href=
"module_animation.html">animation
</a></li>
122 <li class=
""><a href=
"module_autocomplete.html">autocomplete
</a></li>
124 <li class=
""><a href=
"module_button.html">button
</a></li>
126 <li class=
""><a href=
"module_calendar.html">calendar
</a></li>
128 <li class=
""><a href=
"module_connection.html">connection
</a></li>
130 <li class=
""><a href=
"module_container.html">container
</a></li>
132 <li class=
""><a href=
"module_datasource.html">datasource
</a></li>
134 <li class=
""><a href=
"module_datatable.html">datatable
</a></li>
136 <li class=
""><a href=
"module_dom.html">dom
</a></li>
138 <li class=
""><a href=
"module_dragdrop.html">dragdrop
</a></li>
140 <li class=
""><a href=
"module_element.html">element
</a></li>
142 <li class=
""><a href=
"module_event.html">event
</a></li>
144 <li class=
""><a href=
"module_history.html">history
</a></li>
146 <li class=
""><a href=
"module_logger.html">logger
</a></li>
148 <li class=
""><a href=
"module_menu.html">menu
</a></li>
150 <li class=
""><a href=
"module_slider.html">slider
</a></li>
152 <li class=
""><a href=
"module_tabview.html">tabview
</a></li>
154 <li class=
""><a href=
"module_treeview.html">treeview
</a></li>
156 <li class=
""><a href=
"module_yahoo.html">yahoo
</a></li>
163 <li class=
""><a href=
"YAHOO.util.Anim.html">YAHOO.util.Anim
</a></li>
164 <li class=
""><a href=
"YAHOO.util.AnimMgr.html">YAHOO.util.AnimMgr
</a></li>
165 <li class=
""><a href=
"YAHOO.util.Bezier.html">YAHOO.util.Bezier
</a></li>
166 <li class=
""><a href=
"YAHOO.util.ColorAnim.html">YAHOO.util.ColorAnim
</a></li>
167 <li class=
""><a href=
"YAHOO.util.Easing.html">YAHOO.util.Easing
</a></li>
168 <li class=
""><a href=
"YAHOO.util.Motion.html">YAHOO.util.Motion
</a></li>
169 <li class=
""><a href=
"YAHOO.util.Scroll.html">YAHOO.util.Scroll
</a></li>
176 <li class=
""><a href=
"Anim.js.html">Anim.js
</a></li>
177 <li class=
""><a href=
"AnimMgr.js.html">AnimMgr.js
</a></li>
178 <li class=
""><a href=
"Bezier.js.html">Bezier.js
</a></li>
179 <li class=
""><a href=
"ColorAnim.js.html">ColorAnim.js
</a></li>
180 <li class=
""><a href=
"Easing.js.html">Easing.js
</a></li>
181 <li class=
""><a href=
"Motion.js.html">Motion.js
</a></li>
182 <li class=
"selected"><a href=
"Scroll.js.html">Scroll.js
</a></li>
195 Copyright
© 2007 Yahoo! Inc. All rights reserved.