Показать сообщение отдельно
  #7 (permalink)  
Старый 16.06.2020, 15:38
Профессор
Отправить личное сообщение для Nexus Посмотреть профиль Найти все сообщения от Nexus
 
Регистрация: 04.12.2012
Сообщений: 3,802

<nav class="nav"></nav>
 
<section class="container" style="height: 1000px; background: green"></section>
<section class="container" style="height: 1000px; background: yellow"></section>
<section class="container" style="height: 1000px; background: blue"></section>

<style>
    nav {
      background: red;
      position: fixed;
      top: 0;
      left: 0;
      height: 50px;
      width: 100%;
      z-index: 1;
    }
    
    .active {
        opacity: 0.25;
    }
</style>

<script>
    var observer = new IntersectionObserver(function(entries, observer) {
      entries.forEach(function (entry) {
        entry.target.classList[entry.isIntersecting ? 'add' : 'remove']('active');
      });
    }, {threshold: 0.25});

    document.querySelectorAll('.container').forEach(function(node) {
      observer.observe(node);
    });
</script>
Ответить с цитированием