Danilkin500,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.floating.fixed {
position: fixed;
top: 50px;
}
body{
height: 2000px;
}
.floating{
position: relative;
background-color: #FF0000;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function(){
$(window).scroll(function() {
var top = $(document).scrollTop() + $(window).height()+ 100;
if (top > $(document).height()) $('.floating').removeClass('fixed');
else $('.floating').addClass('fixed');
});
});
</script>
</head>
<body>
<div class="floating fixed">123</div>
</body>
</html>