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

Sergey-web92,
что не так?
<!DOCTYPE html>

<html>
<head>
    <title>Untitled</title>
    <meta charset="utf-8">
    <style type="text/css">
    body{
        height: 1000px;
    }

    </style>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <script>
$(document).ready(function() {

    let stickyNavTop = $('.header-laptop').offset().top;

    $('.page-header').height($('.page-header').height());

    $(window).scroll(function(){
        if ($(window).scrollTop() >= stickyNavTop) {
            $('.header-laptop').addClass('fixed-header');
        } else {
            $('.header-laptop').removeClass('fixed-header');
        }
    });
});

    </script>
</head>

<body>
<header class="page-header">
        <!-- top-banner -->
        <section class="top-banner is-active">
                <span class="top-banner__description">some text</span>
        </section>
        <!-- header laptop -->
        <section class="header-laptop">
                <h1>Этот блок должен быть stiky</h1>
        </section>
</header>
<main></main>


<style>
.top-banner {
    height: 50px;
    position: relative;
    background-color: gray;
}

.header-laptop {
    background-color: yellowgreen;
    height: 80px;
    width: 100%;
}

.fixed-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 10;
}

main {
    background-color: tan;
    width: 100%;
    height: 300px;
}

</style>
</body>

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