I have created a div to limit the drag-able area inside the div. The main issue is when the icon is dragged up and down in the area, the area does not scroll with the icon but the icon gets hidden where screen ends. I have seen many tutorials for this but still unable to solve it. I am not sure if it is possible. please help me solving this. Thank you.
var maxDragX = 200 - $('.slide').outerWidth();
var maxDragY = 200 - $('.slide').outerHeight();
Draggable.create('.slide', {
bounds: $('#grabbable-area')
});
$(window).resize(function(){
Draggable.get('.slide').applyBounds("#grabbable-area");
});
#grabbable-area{
display: block;
position: relative;
min-height: 1000px;
width: 80%;
margin-left: 10%;
margin-right: 10%;
border: solid 1px red;
background: grey;
}
.slide{
display: block;
position: absolute;
height: 100px;
width: 100px;
background: red;
}
.green{
cursor: pointer; /* fallback if grab cursor is unsupported */
cursor: pointer;
cursor: -moz-grab;
cursor: -webkit-grab;
}
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Drag</title>
</head>
<body>
<div id="grabbable-area">
<div class="slide one green"></div>
</div>
<link rel="stylesheet" href="grabb.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/utils/Draggable.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js"></script>
<script type="text/javascript" src="grabbb.js"></script> <!-- //don't move it from here for proper grabbing -->
</body>
</html>