processes.indexOf( 'scroll' ) != -1 ){
// scrolling
var left = this.getScrollLeft();
var top = this.getScrollTop();
if( // damn close
( Math.abs( left - this.scrolling_to[0] ) <= 1 &&
Math.abs( top - this.scrolling_to[1] ) <= 1 ) ||
// can't scroll any farther
( this.scroll_cache &&
( this.scroll_cache[0] == left &&
this.scroll_cache[1] == top ) ) ){
CHAPTER 8 n CASE STUDY: FAQ FACELIFT 184
trace( 'wrapping the scroll()' );
window.scrollTo( this.scrolling_to[0], this.scrolling_to[1] );
clearInterval( this.timer.scroll );
this.scroll_cache = null;
this.processes = this.processes.without( 'scroll' );
} else {
trace( 'scrolling()' );
window.scrollTo( left + ( this.scrolling_to[0] - left )/2,
top + ( this.scrolling_to[1] - top )/2 );
this.scroll_cache = [ left, top ];
}
} else {
trace( 'starting the scroll()' );
this.processes.push( 'scroll' );
this.timer.scroll = setInterval( 'FAQ.scroll()', 100 );
}
},
You define yet another timer (FAQ.timer.scroll) to repeatedly trigger FAQ.scroll() at
100ms intervals to smoothly move you down the page to the destination coordinates
set in FAQ.scrolling_to.
2. Those coordinates are set in FAQ.goTo() by using another helper method, FAQ.getDT(),
before calling FAQ.scroll(). FAQ.getDT() returns a reference to the DT associated with
the dd being opened. FAQ.goTo() uses this reference to get the dt element??™s position
using Prototype??™s Position.
Pages:
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261