Scroll(); :: WebCodes.Ru — хранилище кодов, js
imgПолучить кодimgСкопировать кодimgСсылки

Scroll();

Опубликовано 04.09.2010 в 12:16, гостем
var Scroll = function ( element, to, time, callback ) {
	var hasX = 'x' in to,
	hasY = 'y' in to,
	x = [], y = [],
	from = [ element.scrollTop, element.scrollLeft ],
	start = new Date().getTime(),
	now, progress;
	if ( hasX ) {
		x = to.x instanceof Array ? to.x : [ to.x, function ( progress ) {
			return progress;
		} ];
		}
	if ( hasY ) {
		y = to.y instanceof Array ? to.y : [ to.y, function ( progress ) {
			return progress;
		} ];
		
	}
	setTimeout(function() {
		now = (new Date().getTime()) - start;
		progress = now / time;
		if ( hasX ) {
			element.scrollLeft = ( x[0] - from[0] ) * x[1]( progress ) + from[0];
		}
		if ( hasY ) {
			element.scrollTop = ( y[0] - from[0] ) * y[1]( progress ) + from[0];
		}
		if (progress < 1) {
			setTimeout(arguments.callee, 10);
		} else {
			callback();
		}
    }, 10);

};
Valid XHTML 1.1Page Ranking Tool
WebCodes.ru — хранилище кодов © 2009-2010 г.
Все права защищены.
Хостинг от uCoz