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

Зосимов,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
   .bz{
    height: 300px;
    width: 100px;
    font-size: 22px;
    line-height: 44px;
    color: #FFFFFF;
    background-color: #8B4513;
    text-align: center;
    margin-top: 30px;
   }
  p{
    height: 2000px;
  }
  .worked {
    background-color: #FF00FF;
  }

  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

  <script>
$(function() {

    function checkViewport(el) {
    var H = document.documentElement.clientHeight,
        pos = el.getBoundingClientRect();
        return pos.top  > 0 && pos.bottom  < H
    }

    $(window).scroll(function() {
        $('.bz:not(.worked)').each(function(indx, el) {
            var visibility = checkViewport(el);
            if(visibility) {$(el).addClass('worked');
            // load data
            }

        })
    })
});
  </script>
</head>

<body>
<p></p>
<div class="bz" >0</div>
<div class="bz" >0</div>
<div class="bz" >0</div>
<p></p>
</body>
</html>
Ответить с цитированием