Drag a zoomed image within a div clipping mask using jQuery draggable?

前端 未结 2 870
北荒
北荒 2021-01-31 12:04

I\'m creating an interface to allow a user to zoom in on an image and drag the zoomed version around within a clipping mask div.

I have a div 200px by 200px

2条回答
  •  醉酒成梦
    2021-01-31 12:43

    $(this).draggable({
        drag: function(event, ui) {
            if (ui.position.top > 0) {
                ui.position.top = 0;
            }
            var maxtop = ui.helper.parent().height() - ui.helper.height();
            if ( ui.position.top < maxtop) {
                ui.position.top = maxtop;
            }
            if ( ui.position.left > 0) {
                ui.position.left = 0;
            }
            var maxleft = ui.helper.parent().width() - ui.helper.width();
            if ( ui.position.left < maxleft) {
                ui.position.left = maxleft;
            }
        }
    });
    

提交回复
热议问题