JSFiddle - React, Tailwind, and code Playground

by roXon

HTML

<div class="image_drag">

    <img src="http://www.prelovac.com/vladimir/wp-content/uploads/2008/03/example.jpg" />
    
</div>

CSS

.image_drag{
    width:250px;
    height:130px;
    border:2px solid #555;
    overflow:hidden;
    margin:30px auto;
}

JavaScript

$(".image_drag img").draggable({

    stop: function(ev, ui) {
        var hel = ui.helper, pos = ui.position;
        //horizontal
        var h = -(hel.outerHeight() - $(hel).parent().outerHeight());
        if (pos.top >= 0) {
            hel.animate({ top: 0 });
        } else if (pos.top <= h) {
            hel.animate({ top: h });
        }
        // vertical
        var v = -(hel.outerWidth() - $(hel).parent().outerWidth());
        if (pos.left >= 0) {
            hel.animate({ left: 0 });
        } else if (pos.left <= v) {
            hel.animate({ left: v });
        }
    }

});