jQuery Sortable without jQuery UI

前端 未结 10 1937
长情又很酷
长情又很酷 2021-02-01 22:16

I am in need of \"Sortable Drag & Drop\" functionality and I\'m using jQuery. I can\'t really use jQuery UI, because for this project it would be an overhead (I\'d need to a

10条回答
  •  伪装坚强ぢ
    2021-02-01 23:01

    If you want no frills one then I found this one the best: http://jsfiddle.net/erikdana/Nkykq/3/ upto http://jsfiddle.net/erikdana/Nkykq/6/

    very very light and up to the point.

    js

    $('#box').bind({
        mousedown: function() {
            $(document).mousemove(function(e) {
                $('#box').css({
                    top: e.pageY - 10,
                    left: e.pageX - 20
                });
            });
        },
        mouseup: function() {
            $(document).unbind(mousedown);
            var box = $('#box').css('top');
            if (box > '100') {
                $('#box').css({width: '100px'});
            };
        }
    });
    

    css

    div {width:50px;height:50px;background:blue;position:absolute; cursor:move;}
    div:focus { cursor:move;}
    

提交回复
热议问题