How to Change the Look of Resize Handles

How can I change the look of resize handles?

This is a tough one. There is no way of styling this specific control. Even if you force a different appearance under webkit you still get the damn resize handle:

http://jsfiddle.net/qw73n/

You can, however, work around it and place a background image in the bottom left corner:

http://jsfiddle.net/q5kdr/

But the handler will still appear on top of it.

I'm afraid the only alternative is using jQuery UI resizable:

http://jqueryui.com/demos/resizable/

Is there a way to change the CSS resize corner's position?

Here's one starting point. I essentially created a custom resize icon in the upper right corner. I then used 'mousedown', 'mousemove' and 'mouseup' events to track resizing activity. You might be able to do something similar using 'drag' and related events.

Note the 'mousedown' is on the resize icon, while 'mousemove' and 'mouseup' are on the document body (or some other larger element behind the resizable div).

I've hard-coded the width and height in the JavaScript for the sake of simplicity. That means those values exist in two different places which is not good. You should probably put them only in JavaScript or only in CSS, not in both as I have done.

I needed to put the resizable div into a container that filled the body. Otherwise 'mousemove' events outside of the resizable div were not registered. This might not be an issue if you already have other content "behind" your absolutely positioned resizable element.

For your information: I also initially tried using the native resize functionality. I used transform: rotate(-90deg) to move the resize corner to the upper right, then put in an inner div with transform: rotate(90deg) to make the inside content the right-way-up again. However, while this put the resize corner in the correct place, the resizing itself was completely messed up, as the mouse movements and the actually resizing itself were off by 90 degrees. It's a little hard to describe in words, but suffice it to say that, without some major re-working (or perhaps some brilliant code or hidden function) I couldn't get that strategy to work.

var

doc = document,

ht = 400,

wd = 400,

main = document.querySelector("#resizable"),

x, y, dx, dy;

var startResize = function(evt) {

x = evt.screenX;

y = evt.screenY;

};

var resize = function(evt) {

dx = evt.screenX - x;

dy = evt.screenY - y;

x = evt.screenX;

y = evt.screenY;

wd += dx;

ht -= dy;

main.style.width = wd + "px";

main.style.height = ht + "px";

};

rsz.addEventListener("mousedown", function(evt) {

startResize(evt);

doc.body.addEventListener("mousemove", resize);

doc.body.addEventListener("mouseup", function() {

doc.body.removeEventListener("mousemove", resize);

});

});
#container {

position: absolute;

border: solid red 1px;

margin: 0;

height: 100%;

width: 100%;

}

#resizable {

display: block;

font-size: 9pt;

position: absolute;

bottom: 50px;

left: 20px;

padding: 10px;

min-height: 0;

min-width: 0;

border: solid 1px black;

width: 400px;

height: 400px;

overflow-x: auto;

overflow-y: hidden;

}

#rsz {

position: absolute;

right: 0;

top: 0;

width: 20px;

height: 20px;

background-color: rgba(255, 0, 0, 0.5);

}

#original {}
<div id="container">

<div id="resizable">

<div id="rsz"></div>

(some content)

</div>

</div>

how to change the style of resizing?

There's no default way to do this in css. However jQuery UI offers a solution if you use their resizable function. The e and w stands for east and west.

divElement.resizable({
handles: 'e, w'
});​

Here's a working fiddle: http://jsfiddle.net/nick_craver/bx2mk/

CSS Resize handles with resize: both property

Check out this post it is the same question: HTML5/CSS3 - Change the look of resize handles

However what it comes down to is that it is not possible to do it, however there is a workaround that is using a background image:

textarea {
height: 300px;
width: 300px;
position: relative;
background: #fff url(http://merchantmomphotoeditor.com/pixenate/docs/resize_handle2.gif) 100% 100% no-repeat;
}

see http://jsfiddle.net/q5kdr/

How to change default appearance of Fabric.js resize handles?

You can override the default Object control properties globally and set them as per your preference. Here's how your code will look like:

fabric.Object.prototype.set({
transparentCorners: false,
borderColor: '#ff00ff',
cornerColor: '#ff0000'
});

You can set this in the beginning of your code. This will override the default styling of controls and will be applied everywhere. You can find a working fiddle here: http://jsfiddle.net/apyeLeut/1/



Related Topics



Leave a reply



Submit