JSFiddle - React, Tailwind, and code Playground

HTML

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

<div id="page">
 <div id="header"><h1>header</h1></div> 
    <div id="body" >
        <h1>content top -> when scrolling up the box should STOP here (at the line right above this text)</h1>
        <div id="dialog" title="Detailed FeedBack">I'm in a dialog </div>

        <span style="position: absolute; bottom: 0; ">content bottom -> when scrolling down the box should STOP here (at the line right below this text)</span>

    </div>
    <div id="footer"><h1>footer</h1></div>
    <div id="debug"></div>
</div>

CSS

#page{
    width:800px;
    margin:0 auto;
}
.myPosition1 {
position: 'absolute',
            top: '0px',
            bottom: 'auto',
            Right: '0'

}
.myPosition2 {
           position: 'fixed',
            top: 'auto',
            bottom: 'auto',
            Right: '0'
        }
 .myPosition3 {
         position: 'absolute',
        top: 'auto',
        bottom: '0px',
        Right: '0'
        }
#header{
    border:1px solid blue;
    height:15px;
    margin:8px;
}
#body{
    border:1px solid blue;
    height:5600px;
    margin:8px;
    position: relative;
}
#footer{
    border:1px solid blue;
    height:15px;
    margin:8px;
}
h1,h2{
    padding:16px;
}

#debug {
    position: fixed;
    bottom: 0;
    right: 0;
    height: 100px;
    width: 100px;
    color: red;
}

JavaScript

$(document).ready(function () {
    $("#dialog").dialog();
*        
    var $parent = $('#body');
    var windowHeight = $(window).height();
    var parentAbsoluteTop = $parent.offset().top;
    var parentAbsoluteBottom = parentAbsoluteTop + $parent.height();
    var topStop = parentAbsoluteTop + $( ".selector" ).dialog( "option", "height" );
    
    $('#dialog').dialog({
        width: 300,
        height: 600,
        containment: '#body'
    }).dialog('widget').position({
        my: 'right top',
        at: 'right top',
        of: $('#body')
    });

    $(window).scroll(function (event) {
        var windowBottom = $(window).scrollTop() + windowHeight;

        if (windowBottom < topStop)

        $('.selector').dialog({
            dialogClass: 'myPosition1'
        });
        else if (windowBottom >= topStop && windowBottom <= parentAbsoluteBottom) $('.selector').dialog({
            dialogClass: 'myPosition2'
        });
        else $('.selector').dialog({
            dialogClass: 'myPosition3'
        });

    })
});