How to resize ONLY horizontally or vertically with jQuery UI Resizable?

前端 未结 7 2282
长情又很酷
长情又很酷 2020-12-12 23:29

The only solution I\'ve found is to set the max and min height or width with the current value.

Example:

foo.resizable({ 
  maxHeight: foo.height(),          


        
7条回答
  •  孤街浪徒
    2020-12-12 23:54

    For me solutions with both handles and resize handler worked fine, so user see handle but can resize only horizontally, similar solution should work for vertical. Without bottom right handler user might be unaware that he can resize element.

    When using ui.size.height = ui.originalSize.height; it will not work properly if element changed it's size from initial state.

    foo.resizable({
        // Handles left right and bottom right corner
        handles: 'e, w, se',
        // Remove height style
        resize: function(event, ui) {
            $(this).css("height", '');
        }
    });
    

    For better performance $(this) could be removed:

    var foo = jQuery('#foo');
    foo.resizable({
        // Handles left right and bottom right corner
        handles: 'e, w, se',
        // Remove height style
        resize: function(event, ui) {
            foo.css("height", '');
        }
    });
    

提交回复
热议问题