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

кнопки вверх вниз анимация прокрутки страницы плавный скролинг
Teamur,
<!DOCTYPE HTML>

<html>

<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
  body{
    height: 1500px;
    position: relative;
  }
  .up{
     position: absolute; top: 100%;
  }
   div{
     cursor: pointer;
   }

  </style>
  <script>


function animateScroll(dn) {
    var scrollHeight = Math.max(
            document.body.scrollHeight, document.documentElement.scrollHeight,
            document.body.offsetHeight, document.documentElement.offsetHeight,
            document.body.clientHeight, document.documentElement.clientHeight
        ),
        maxScroll = scrollHeight - document.documentElement.clientHeight,
        from = window.pageYOffset || document.documentElement.scrollTop,
        to = dn ? maxScroll : 0,
        duration = 1000,//время прокрутки
        start = new Date().getTime();

    function delta(progress) {
        return progress;
    }
    setTimeout(function t() {
        var now = (new Date().getTime()) - start;
        var progress = now / duration;
        var result = (to - from) * delta(progress) + from;
        if (progress > 1) result = to;
        window.scrollTo(0, result);
        if (progress < 1)
            setTimeout(t, 10);
    }, 10);

}


 </script>
</head>

<body>
<div onclick="animateScroll(true)">ВНИЗ</div>
<div onclick="animateScroll()"  class="up">ВВЕРХ</div>
</body>

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