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

parallax на видимом блоке
LADYX,
<!DOCTYPE html>
<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style>.header,
.footer,
.parallax {
  height: 1000px;
}

.header,
.footer {
  background-color: pink;
}

.parallax {
  background-color: beige;
}

span {
  text-align: center;
  font-size: 0px;
  position: fixed;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  line-height: 2px;
  margin-top: -1px;
}</style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

  <script>
$(function() {
  var parallax = document.querySelector('.parallax');

  $(window).scroll(function() {
    var {top,bottom} =  parallax.getBoundingClientRect();
    var size = 0;
    if(top < 0 && bottom > window.innerHeight) size = Math.round(-top / (parallax.scrollHeight - window.innerHeight) * 120);
    if(bottom < window.innerHeight) size = 120;
    $('span').css('font-size',  `${size}px`);
  });
})
  </script>
</head>
<body>

<div class="header"></div>
<div class="parallax"><span>Parallax</span></div>
<div class="footer"></div>
</body>
</html>
Ответить с цитированием