jquery drag image

前端 未结 5 440
感动是毒
感动是毒 2021-01-11 19:17

i want to make a draggable image in jquery. first of all my experience with jquery is 0. having said that let me describe what i want to achieve. i have fixed width/height

5条回答
  •  盖世英雄少女心
    2021-01-11 20:11

    Expanding on the answer from PH. this will provide an elastic bounceback whenever the image is dragged to the point the underlying container is exposed:

    stop: function(event, ui) {
            var helper = ui.helper, pos = ui.position;
            var h = -(helper.outerHeight() - $(helper).parent().outerHeight());
            var w = -(helper.outerWidth() - $(helper).parent().outerWidth());
            if (pos.top <= h) {
                helper.animate({ top: h });
            } else if (pos.top > 0) {
                helper.animate({ top: 0 });
            }
            if (pos.left <= w) {
                helper.animate({ left: w });
            } else if (pos.left > 0) {
                helper.animate({ left: 0 });
            }
        }
    

提交回复
热议问题