Показать сообщение отдельно
  #5 (permalink)  
Старый 27.11.2014, 00:23
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,068

Tecvid,
Вариант с замыканием ...
<div id="test" style="background-color: rgb(255, 102, 255); height: 50px; width: 50px"></div>
<script>
function select(selector) {
    var s = typeof selector == "string" ? document.querySelector(selector) : selector;
    this.animate = function(options, duration, delay) {
        var start = (new Date).getTime();
        duration = duration || 500;
        delay = delay || 10;
        if (delay < 10) delay = 10;
        else if (delay > 2E3) delay = 2E3;
        for (var prop in options) {
            var value = options[prop],
                currentValue = parseInt(s.style[prop]);
            +function(a, b, c) {
                return function anim() {
                    var now = (new Date).getTime() - start,
                        progress = now / duration,
                        result = (a - b) * progress + b;
                    s.style[c] = progress < 1 ? result + "px" : a + "px";
                    if (progress < 1) setTimeout(anim, delay)
                }
            }(value, currentValue, prop)()
        }
    };
    return this
};

select('#test').animate({
	width: 100,
	height: 100
}, 2000);
</script>
Ответить с цитированием