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

Moloch,
<!DOCTYPE HTML>

<html>

<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">

  .segment {
    background: #FFCC00;
    width: 100px;
    height: 100px;
    position:  relative;
    float: left;
  }

  </style>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  <script>
 $(function() {
    var defaultCoords = [], rand = function() {
    return Math.floor(Math.random() * 200) + 10;
};
    $(".segment").each(function(indx, s) {
        var e = $(s).offset();
        defaultCoords[indx] = {"pos_x" : e.left, "pos_y" : e.top}
     }).css({"position" : "absolute"}).each(function(indx, s) {
        var e = $(s);
        e.offset({
            left: rand(),
            top: rand()
        })
    })
    function animR()
    {
       $(".segment").each(function(indx, s) {
        var e = $(s);
        e.animate({
            left: defaultCoords[indx]["pos_x"],
            top: defaultCoords[indx]["pos_y"]
        })
    })
    }
    window.setTimeout(animR, 2000)
});
  </script>
</head>

<body>
<div class="segment">1</div>
<div class="segment">2</div>
</body>

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