JSFiddle - React, Tailwind, and code Playground

by pleinx

HTML

<script src="http://bigspotteddog.github.io/ScrollToFixed/jquery-scrolltofixed-min.js"></script>
<div class="page">
    <div class="header">
        Nice Header, Navigation etc pp
    </div>
    <div class="content">
        <h1>Yay! Iam the Productpage</h1>
        
        <div class="box">
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
        </div>
    </div>
    <div class="sidebar">
        <div class="box">
            Nice SidebarBox
        </div>
    </div>
    <div class="footer">
        Nice Footer
    </div>
</div>

CSS

body {
    color: white;
}

.page {
    width: 100%;
}

.header {
    height: 100px;
    background: green;
    margin-bottom: 20px;
}

.content, .sidebar {
    float: left;
}

.content {
    width: 57%;
    border: 1px solid gray;
    color: black;
    margin-bottom: 20px;
}

.content .box {
    margin-top: 20px;
}

.sidebar {
    width: 40%;
    margin-left: 2%;
}

.sidebar .box {
    width: 77%;
    padding: 50px;
    text-align: center;
    background: gray;
    margin-top: 20px;
}

.content .box:first-child, .sidebar .box:first-child {
    margin: 0;
}

.sidebar .box:nth-child(2n) {
    background: darkgray;
}
.footer {
    clear: both;
    height: 80px;
    background: lightgray;
}

JavaScript

$(document).ready(function() {

    // create content boxes
    var contentBoxCtn = 10;
    for (var i = 1 ; i <= contentBoxCtn ; i++) {
        $('.content .box').first().clone().appendTo('.content');
    }    
    
	// create sidebar boxes
    var sidebarBoxCtn = 5;
    for (var i = 1 ; i <= sidebarBoxCtn ; i++) {
        $('.sidebar .box').first().clone().prependTo('.sidebar');
    }
    
	// fixed on top
	var limit = $('.content').position().top + $('.content').outerHeight(true);
    limit = limit - $('.sidebar').outerHeight(true) - 20;

	$('.sidebar').scrollToFixed({ 
        marginTop: function() {
            
            return 20;
            
            var marginTop = $(window).height() - $('.sidebar').outerHeight(true) - 20;
            console.log(marginTop);
            
            if (marginTop >= 0)
                return 20;
            
            return marginTop;
        }, 
        limit: limit
    });
    
});