Показать сообщение отдельно
  #4 (permalink)  
Старый 07.10.2017, 19:30
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,075

animate translateX
Булат Азат улы,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
   .hot{
         border: 1px dashed Gray; padding: 5px; height: 100px; width: 100px;
         background-color: rgba(139, 69, 19, 1);

    }
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script>
$(function() {
$.fn.Timer = function Timer(obj) {
        var def = {
            from: 5E3,
            duration: 5E3,
            to: 0,
            callback: null,
            step: function(now, fx) {
                $(fx.elem).css("transform", "translateX("+(now | 0)+"px)");
            }
        };
        var opt = $.extend({}, def, obj);
        return this.each(function(indx, el) {
            $(el).queue(function() {
                el.n = opt.from;
                $(el).dequeue()
            });
            $(el).animate({
                n: opt.to
            }, {
                easing: "swing",
                duration: opt.duration,
                step: opt.step,
                complete: opt.callback
            })
        })
    };

    $(".hot").Timer({from: 0,
            duration: 5000,
            to: 500})

});
  </script>
</head>

<body>
<style type="text/css">


  </style>
 <div class="hot"></div>

</body>
</html>
Ответить с цитированием