JSFiddle - React, Tailwind, and code Playground

by Intesar Haider

HTML

<div class="header_wrap">
    <ul class="subMenu">
        <li> <a href="#about-us" title="About Us">About Us</a>

        </li>
        <li> <a href="#section-the-team" title="The Team">The Team</a>

        </li>
        <li> <a href="#section-publications" title="Publications">Publications</a>

        </li>
        <li> <a href="#section-affiliations" title="Affiliations">Affiliations</a>

        </li>
        <li> <a href="#section-terms-and-conditions" title="Terms and Conditions">Terms and Conditions</a>

        </li>
    </ul>
</div>
<div class="sections">
    <div class="section_item" id="about-us">
         <h1>About Us</h1>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
    <div class="section_item" id="section-the-team">
         <h1>The team</h1>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's...

CSS

body {
    font-family:'Arial';
    font-size:15px;
    color:#111;
}
.header_wrap {
    background-color:rgba(0, 0, 0, 0.5);
    height:150px;
    text-align:center;
    line-height:150px;
}
.fixed_nav_menu {
    position:fixed;
    top:0;
    width:100%;
    left:0;
}
h1 {
    font-size:30px;
}
.section_item {
    border-bottom:1px solid #ccc;
    margin-bottom:10px;
    padding-bottom:10px;
}
li {
    display: inline-block;
    margin-right:15px;
}
a {
    color:#fff;
    font-weight:bold;
}
a.curM {
    text-decoration:none;
}
a:hover {
    text-decoration:none;
}

JavaScript

jQuery(document).ready(function () {
    $('ul.subMenu li a').click(function () {
        jQuery('ul.subMenu li a.curM').removeClass('curM');
        jQuery(this).addClass('curM');

        var target = $(this).attr('href');

        var getHeaderHeight = jQuery(".header_wrap").outerHeight();
        if(jQuery(".header_wrap").hasClass('fixed_nav_menu'))
        	var scrollTo = $(target).offset().top - getHeaderHeight;
        else
        	var scrollTo = $(target).offset().top - (getHeaderHeight * 2);
        console.log($(target).offset().top +  ' - ' + getHeaderHeight);
        $('html, body').stop().animate({
            'scrollTop': scrollTo
        }, 'fast', 'swing');


    });

    jQuery(window).scroll(function () {
        jQuery('.header_wrap').addClass('fixed_nav_menu');
        if (jQuery(document).scrollTop() == 0) {
            jQuery('.header_wrap').removeClass('fixed_nav_menu');
        }
    });

});