I am using the jQuery-ui library to drag an image/child within a parent container. In theory, I'm trying to replicate the bounds of a webpage in a browser. I want to:
- If the child bottom reaches the parent bottom, I want to prevent further dragging upwards on y-axis.
- If the child top reaches the parent top (which is the initial position on page load), prevent dragging downwards on y-axis.
A quick CodePen to help illustrate where I'm at: https://codepen.io/austin-branham/full/eYGgoNg
My script:
var draggableHeight = $('.draggable').height();
var parentHeight = $('.project-image').height();
$('.draggable').draggable({
axis: "y",
drag: function(e, ui) {
// figure out how far to drag within this function
}
});