Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizable doesn't work correctly after rotation #1

Open
ilyavolodin opened this issue May 22, 2013 · 1 comment
Open

Resizable doesn't work correctly after rotation #1

ilyavolodin opened this issue May 22, 2013 · 1 comment
Labels

Comments

@ilyavolodin
Copy link
Owner

Rotating an element to 180 degrees and then resizing top handle will make it look like you are resizing from the bottom. This is due to the fact that jQuery Resizable is not aware of the rotation angle. I tried to fix it and was able to fix it for the case of 180 degree rotation, but the rest of the angles would require more time investment and quite a bit of math calculations: Here's the code that partially fixes resizable:

if ($.ui.resizable)
{
    var _changeCopy = $.extend({}, $.ui.resizable.prototype._change);

    $.ui.resizable.prototype._change =  {
        newChange: function(event, dx, direction, dy)
        {
            var angle = getAngle(this);
            var convertedAngle = parseInt(angle / 90);
            var axisToAngle = { "s" : 0, "w" : 1, "n" : 2, "e" : 3 };

            if (typeof axisToAngle[direction] == 'undefined' || angle <= 90 || angle >= 270)
            {
                return _changeCopy[direction].call(this, event, dx, dy);
            }

            var angleToAxis = { 0 : "s", 1 : "w", 2: "n", 3: "e" };
            var correctedAxis = axisToAngle[direction] + convertedAngle;
            correctedAxis = correctedAxis % 4;
            return _changeCopy[angleToAxis[correctedAxis]].call(this, event, dx, dy);
        },
        e: function(event, dx)
        {
            return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "e");
        },
        w: function(event, dx)
        {
            return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "w");
        },
        n: function(event, dx, dy)
        {
            return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "n", dy);
        },
        s: function(event, dx, dy)
        {
            return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "s", dy);
        },
        se: function(event, dx, dy)
        {
            return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "se", dy);
        },
        sw: function(event, dx, dy)
        {
            return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "sw", dy);
        },
        ne: function(event, dx, dy)
        {
            return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "ne", dy);
        },
        nw: function(event, dx, dy)
        {
            return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "nw", dy);
        }
    };

    var getAngle = function(widget)
    {
        var rotatable = widget.element.data("uiRotatable");
        return rotatable.angle || 0;
    };
}
@bravoh
Copy link

bravoh commented May 8, 2018

I had faced the same issue with ui-resizable, what worked for me was to create a child div within the div and rotate it, that way, ui-resizable is not rotated but will resize whatever is in the child folder:

in my case .curr was the div with ui-resizable, i only wanted to rotate imges/svgs within it.

let rotate = (deg) =>  {

        let cssVal = 'rotate(' + deg + 'deg)';

        $('.curr img').css({
            'transform': cssVal,
            "-webkit-transform": cssVal,
            "-moz-transform": cssVal,
            "-ms-transform": cssVal,
            "-o-transform": cssVal
        });

        $('.deg').val(deg + ' deg');

        $('.curr svg').css(
            {
                'transform': cssVal,
                "-webkit-transform": cssVal,
                "-moz-transform": cssVal,
                "-ms-transform": cssVal,
                "-o-transform": cssVal
            });
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants